Skip to content

Commit 4ab7e48

Browse files
committed
provide hash-map and map?
1 parent e3480cd commit 4ab7e48

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clojure/clojure.rkt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
-> ->>
2626
partial comp complement constantly
2727
vector str
28+
hash-map map?
2829
hash-set set?
2930
map true false nil nth)
3031

@@ -162,7 +163,7 @@
162163
(datum->syntax
163164
#'(kv ...)
164165
(apply append (syntax->datum #'(kv.pair ...))))
165-
#'(hash key-vals ...)]
166+
#'(hash-map key-vals ...)]
166167
[(_ proc:expr arg:expr ...)
167168
#'(#%app proc arg ...)]))
168169

@@ -221,6 +222,12 @@
221222
[(char? v) (rkt:string v)]
222223
[else (format "~s" v)])) ;; FIXME implement clojure printer and pr-str
223224

225+
(define (hash-map . args)
226+
(apply hash args))
227+
228+
(define (map? v)
229+
(and (hash? v) (immutable? v)))
230+
224231
(define (hash-set . args)
225232
(apply rkt:set args))
226233

clojure/tests/test.rkt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
(check-true (immutable? [1 2 3]))
99
(check-true (immutable? '[1 2 3]))
1010
(check-true (immutable? (vector 1 2 3)))
11-
(displayln {:a 5 :b 7})
12-
(displayln {:a 5, :b 7})
1311
(check-equal? [1,2,3] [1 2 3])
1412
(check-equal? [1 2 (+ 1 2)] [1 2 3])
1513
(check-equal? '[1 2 (+ 1 2)] [1 2 '(+ 1 2)])
1614
(check-equal? [1 2 [3]] (vector 1 2 (vector 3)))
1715

16+
(displayln {:a 5 :b 7})
17+
(displayln {:a 5, :b 7})
18+
(check-equal? {:a 5 :b 7} (hash-map ':a 5 ':b 7))
19+
(check-pred map? {:a 5 :b 7})
20+
1821
(check-pred char? \a)
1922

2023
(check-pred set? #{1 2 3})

0 commit comments

Comments
 (0)