Clojure 中的 struct函数

首页 / Clojure入门教程 / Clojure 中的 struct函数

此函数用于定义由defstruct操作创建的类型的结构对象 。

struct - 语法

(struct structname values)

参数      -  " structname"是要赋予结构的名称, "values"是需要分配给结构键值的值。

返回值  -  返回一个结构对象 ,其值映射到结构的键。

struct - 示例

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (defstruct Employee :EmployeeName :Employeeid)
   (def emp (struct Employee "Learnfk" 1))
   (println emp))
(Example)

上面的程序产生以下输出。

{:EmployeeName Learnfk, :Employeeid 1}

可以清楚地看到struct函数中提供的值已分配给Employee对象的键。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

AI技术内参 -〔洪亮劼〕

持续交付36讲 -〔王潇俊〕

Linux实战技能100讲 -〔尹会生〕

说透中台 -〔王健〕

安全攻防技能30讲 -〔何为舟〕

跟着高手学复盘 -〔张鹏〕

说透区块链 -〔自游〕

反爬虫兵法演绎20讲 -〔DS Hunter〕

互联网人的数字化企业生存指南 -〔沈欣〕

好记忆不如烂笔头。留下您的足迹吧 :)