目录

struct-map

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

语法 (Syntax)

以下是语法。

(struct-map structname keyn valuen …. )

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

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

例子 (Example)

以下程序显示了如何使用它的示例。

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

输出 (Output)

上述程序产生以下输出。

{:EmployeeName John, :Employeeid 1}
↑回到顶部↑
WIKI教程 @2018