当前位置: 首页 > 文档资料 > Clojure 中文教程 >

defstruct

优质
小牛编辑
176浏览
2023-12-01

该函数用于定义所需的结构。

语法 (Syntax)

以下是语法。

(defstruct structname keys)

Parameters - 'structname'是要赋予结构的名称。 'keys'是需要成为结构一部分的键。

Return Value - 返回结构对象。

例子 (Example)

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

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (println (defstruct Employee :EmployeeName :Employeeid)))
(Example)

请注意,上面的函数仅用于创建结构,我们将看到更多可用于处理结构的函数。

输出 (Output)

上述程序产生以下输出。

#'clojure.examples.example/Employee