Clojure 中的 Adding a New Key to the

首页 / Clojure入门教程 / Clojure 中的 Adding a New Key to the

由于结构是不可变的,因此可以将另一个键添加到结构中的唯一方法是创建新结构。

示例

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

在上面的示例中,我们通过创建新的结构对象将名为EmployeeRank的新键关联到该结构。

无涯教程网

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

链接:https://www.learnfk.comhttps://www.learnfk.com/clojure/clojure-adding-key-to-structure.html

来源:LearnFk无涯教程网

{:EmployeeName Learnfk, :Employeeid 1, :EmployeeRank A}

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

技术教程推荐

AI技术内参 -〔洪亮劼〕

面试现场 -〔白海飞〕

深入浅出计算机组成原理 -〔徐文浩〕

SQL必知必会 -〔陈旸〕

全栈工程师修炼指南 -〔熊燚(四火)〕

DDD实战课 -〔欧创新〕

如何成为学习高手 -〔高冷冷〕

李智慧 · 高并发架构实战课 -〔李智慧〕

商业思维案例笔记 -〔曹雄峰〕

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