hashmaps are now first class objects in the language
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
(define hm/set! hash-map-set!)
|
||||
(define hm/get hash-map-get)
|
||||
|
||||
(define-syntax (pe expr)
|
||||
`(print ',expr "evaluates to" ,expr))
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
(define hm/set! hash-map-set!)
|
||||
|
||||
(define hm/get hash-map-get)
|
||||
|
||||
(define-syntax (pe expr) `(print ',expr "evaluates to" ,expr))
|
||||
|
||||
(define-syntax (when condition . body) :doc "Special form for when multiple actions should be done if a\ncondition is true.\n\n{{{example_start}}}\n(when (not ())\n (print "Hello ")\n (print "from ")\n (print "when!"))\n\n(when ()\n (print "Goodbye ")\n (print "World!"))\n{{{example_end}}}\n" (if (= (rest body) ()) `(if ,condition (unquote-splicing body) nil) `(if ,condition (begin (unquote-splicing body)) nil)))
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
(define hm1 (create-hash-map))
|
||||
|
||||
(hm/set! hm1 1 "a")
|
||||
(hm/set! hm1 "a" (lambda (x) (+ x 1)))
|
||||
|
||||
(assert (= ((hm/get hm1 (hm/get hm1 1)) 2) 3))
|
||||
|
||||
(define hm2 (create-hash-map))
|
||||
(hm/set! hm2 'yes :yes)
|
||||
(hm/set! hm2 :yes 'yes)
|
||||
|
||||
(assert (= (hm/get hm2 'yes) :yes))
|
||||
(assert (= (hm/get hm2 :yes) 'yes))
|
||||
(assert (= (hm/get hm2 (hm/get hm2 'yes)) 'yes))
|
||||
(assert (= (hm/get hm2 (hm/get hm2 :yes)) :yes))
|
||||
(assert (= (hm/get hm2 (hm/get hm2 (hm/get hm2 'yes))) :yes))
|
||||
(assert (= (hm/get hm2 (hm/get hm2 (hm/get hm2 :yes))) 'yes))
|
||||
|
||||
(define hm3 (create-hash-map))
|
||||
(hm/set! hm3 + 'plus)
|
||||
(hm/set! hm3 - 'minus)
|
||||
|
||||
(assert (= (hm/get hm3 +) 'plus))
|
||||
(assert (= (hm/get hm3 -) 'minus))
|
||||
Reference in New Issue
Block a user