Clojure-accessing-individual-fields
提供:Dev Guides
Clojure-個々のフィールドへのアクセス
構造オブジェクトと共にキーにアクセスすることにより、構造の個々のフィールドにアクセスできます。
構文
構文は次のとおりです。
:key structure-name
パラメータ-「キー」は構造内のキー値です。 「構造名」は、それぞれのキーである構造です。
戻り値-キーに関連付けられた値が返されます。 これがどのように使用されるかの例は、次のプログラムに示されています。
例
(ns clojure.examples.example
(:gen-class))
(defn Example []
(defstruct Employee :EmployeeName :Employeeid)
(def emp (struct-map Employee :EmployeeName "John" :Employeeid 1))
(println (:Employeeid emp))
(println (:EmployeeName emp)))
(Example)
出力
上記のプログラムは、次の出力を生成します。
1
John