可以通过与结构对象一起访问键来访问结构的各个字段。
:key structure-name
参数 - "key"是结构中的键值, "structure-name"是作为相应关键字的结构。
返回值 - 将返回与键关联的值。以下程序显示了有关如何使用它的示例。
(ns clojure.examples.example (:gen-class)) (defn Example [] (defstruct Employee :EmployeeName :Employeeid) (def emp (struct-map Employee :EmployeeName "Learnfk" :Employeeid 1)) (println (:Employeeid emp)) (println (:EmployeeName emp))) (Example)
上面的程序产生以下输出。
1 Learnfk
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)