File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1281,6 +1281,7 @@ and implements IAssociative, ILookup and IObject."
12811281 fields (transduce (map (comp keyword name)) conj field- syms)
12821282 type - from - map `(defn ~ map - ctor- name [m]
12831283 (apply ~ ctor- name (map # (get m %) ~fields)))
1284+ meta- gs (gensym " meta" )
12841285 default- bodies [' IAssociative
12851286 (- make- record- assoc- body ctor- name fields)
12861287
@@ -1299,6 +1300,13 @@ and implements IAssociative, ILookup and IObject."
12991300 [k `(get- field ~ self - nm ~ k- nm)])
13001301 fields)
13011302 not - found# )))
1303+
1304+ ' IMeta
1305+ `(- with - meta [self # ~meta-gs]
1306+ (new ~ nm
1307+ ~ @(conj field- syms meta- gs)))
1308+ `(- meta [self # ] __meta)
1309+
13021310 ' IObject
13031311 `(- str [self # ]
13041312 (str " <" ~ (name nm) " " (reduce # (assoc %1 %2 (%2 self#)) {} ~fields) ">"))
@@ -1310,9 +1318,13 @@ and implements IAssociative, ILookup and IObject."
13101318 `(- hash [self ]
13111319 (hash [~ @field- syms]))
13121320 `IRecord]
1313- deftype- decl `(deftype ~ nm ~ fields ~ @default- bodies ~ @body)]
1321+ deftype- decl `(deftype ~ nm ~ (conj fields ' __meta) ~@default-bodies ~@body)
1322+ ctor `(defn ~ ctor- name ~ field- syms
1323+ (new ~ nm
1324+ ~ @(conj field- syms nil)))]
13141325 `(do ~ type - from - map
1315- ~ deftype- decl)))
1326+ ~ deftype- decl
1327+ ~ ctor)))
13161328
13171329(defn print
13181330 {:doc " Prints the arguments, seperated by spaces."
Original file line number Diff line number Diff line change 5353 (t/ assert (contains? t :one))
5454 (t/ assert (contains? t :two))
5555 (t/ assert (contains? t :three))))
56+
57+ (t/ deftest test- record- metadata
58+ (t/ assert = nil (meta t1))
59+ (t/ assert = :foo (- > t1 (with - meta :foo) meta)))
You can’t perform that action at this time.
0 commit comments