Clojure - 结构映射



此函数用于通过明确定义哪些值分配给结构中的哪些键来专门为键值分配值。

语法

以下是语法。

(struct-map structname keyn valuen …. )

参数 - 'structname' 是要赋予结构的名称。'keyn 和 valuen' 是需要分配给结构的键值。

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

示例

以下程序展示了如何使用它。

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

输出

以上程序产生以下输出。

{:EmployeeName John, :Employeeid 1}
clojure_structmaps.htm
广告

© . All rights reserved.