File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 64
64
(defmacro define-record-type
65
65
" Attach doc properties to the type and the field names to get reasonable docstrings."
66
66
[?type ?constructor-call ?predicate ?field-specs & ?opt+specs]
67
- (when-not (and (list? ?constructor-call)
68
- (not (empty? ?constructor-call)))
67
+ (when-not (or (and (list? ?constructor-call)
68
+ (not (empty? ?constructor-call)))
69
+ (symbol? ?constructor-call))
69
70
(throw (throw-illegal-argument-exception (str " constructor call must be a list in " *ns* " " (meta &form)))))
70
71
(when-not (vector? ?field-specs)
71
72
(throw (throw-illegal-argument-exception (str " field specs must be a vector in " *ns* " " (meta &form)))))
100
101
:else
101
102
(throw (throw-illegal-argument-exception (str " invalid field spec " spec " in " *ns* " " (meta &form))))))))
102
103
103
- ?constructor (first ?constructor-call)
104
- ?constructor-args (rest ?constructor-call)
104
+ [?constructor & ?constructor-args] (cond
105
+ (list? ?constructor-call)
106
+ ?constructor-call
107
+
108
+ (symbol? ?constructor-call)
109
+ (concat [?constructor-call]
110
+ (map first ?field-triples)))
105
111
?constructor-args-set (set ?constructor-args)
106
112
document (fn [n doc]
107
113
(vary-meta n
Original file line number Diff line number Diff line change 32
32
(is (thrown? Throwable
33
33
(kar (FakePare. 1 2 )))))
34
34
35
+
36
+ ; ; Omit constructor args
37
+
38
+ (define-record-type Schmare
39
+ schmons
40
+ schmare?
41
+ [a schmar
42
+ b schmdr])
43
+
44
+ (deftest simple-omit
45
+ (let [r (schmons 1 2 )]
46
+ (is (schmare? r))
47
+ (is (= 1 (schmar r)))
48
+ (is (= 2 (schmdr r)))))
49
+
50
+
51
+ ; ; Uninstantiated fields
52
+
35
53
(define-record-type Pu
36
54
(make-pu c a)
37
55
pu?
You can’t perform that action at this time.
0 commit comments