we have a new parser and can parse [] and {} for vectors and hm's
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
(define-module emoji
|
||||
:exports (get)
|
||||
|
||||
(define emoji-map (create-hash-map))
|
||||
(define emoji-map (hash-map))
|
||||
(hm/set! emoji-map :grinning-face '😀)
|
||||
(hm/set! emoji-map :grinning-face-with-big-eyes '😃)
|
||||
(hm/set! emoji-map :grinning-face-with-smiling-eyes '😄)
|
||||
|
||||
+3
-3
@@ -5,11 +5,11 @@
|
||||
`(set-type!
|
||||
(define
|
||||
;; The function definition
|
||||
(,(string->symbol (concat-strings "make-" (symbol->string name))) @members)
|
||||
(,(string->symbol (concat-strings "make-" (symbol->string name))) ,@members)
|
||||
;; The docstring
|
||||
,(concat-strings "This is the handle to an object of the class " (symbol->string name))
|
||||
;; the body
|
||||
@body
|
||||
,@body
|
||||
(let ,(zip members members)
|
||||
(set-type!
|
||||
(lambda args
|
||||
@@ -22,4 +22,4 @@
|
||||
:constructor)))
|
||||
|
||||
(define-syntax (-> obj meth . args)
|
||||
`(,obj ',meth @args))
|
||||
`(,obj ',meth ,@args))
|
||||
|
||||
+14
-14
@@ -33,22 +33,22 @@ condition is true.
|
||||
{{{example_end}}}
|
||||
"
|
||||
(if (= (rest body) ())
|
||||
`(if ,condition @body nil)
|
||||
`(if ,condition (begin @body) nil)))
|
||||
`(if ,condition ,@body nil)
|
||||
`(if ,condition (begin ,@body) nil)))
|
||||
|
||||
(define-syntax (unless condition . body)
|
||||
:doc "Special form for when multiple actions should be done if a
|
||||
condition is false."
|
||||
(if (= (rest body) ())
|
||||
`(if ,condition nil @body)
|
||||
`(if ,condition nil (begin @body))))
|
||||
`(if ,condition nil ,@body)
|
||||
`(if ,condition nil (begin ,@body))))
|
||||
|
||||
(define-syntax (n-times times action)
|
||||
:doc "Executes action times times."
|
||||
(define (repeat times elem)
|
||||
(unless (> 1 times)
|
||||
(pair elem (repeat (- times 1) elem))))
|
||||
`(begin @(repeat times action)))
|
||||
`(begin ,@(repeat times action)))
|
||||
|
||||
(define-syntax (let bindings . body)
|
||||
(define (unzip lists)
|
||||
@@ -64,7 +64,7 @@ condition is false."
|
||||
|
||||
(define unzipped (unzip bindings))
|
||||
|
||||
`((,lambda ,(first unzipped) @body) @(first (rest unzipped))))
|
||||
`((,lambda ,(first unzipped) ,@body) ,@(first (rest unzipped))))
|
||||
|
||||
(define-syntax (cond . clauses)
|
||||
(define (rec clauses)
|
||||
@@ -76,7 +76,7 @@ condition is false."
|
||||
(error :syntax-error "There are additional clauses after the else clause!")
|
||||
(pair 'begin (rest (first clauses)))))
|
||||
`(if ,(first (first clauses))
|
||||
(begin @(rest (first clauses)))
|
||||
(begin ,@(rest (first clauses)))
|
||||
,(rec (rest clauses))))))
|
||||
(rec clauses))
|
||||
|
||||
@@ -91,7 +91,7 @@ condition is false."
|
||||
(error :syntax-error "There are additional clauses after the else clause!")
|
||||
(pair 'begin (rest (first clauses)))))
|
||||
`(if (member? ,var ',(first (first clauses)))
|
||||
(begin @(rest (first clauses)))
|
||||
(begin ,@(rest (first clauses)))
|
||||
,(rec (rest clauses))))))
|
||||
(rec clauses))
|
||||
|
||||
@@ -149,14 +149,14 @@ condition is false."
|
||||
(let ((name (first args))
|
||||
(lambda-list (rest args))
|
||||
(arg-names (get-arg-names (rest args))))
|
||||
`(define (,name @arg-names)
|
||||
(assert-types= @lambda-list)
|
||||
@body)))
|
||||
`(define (,name ,@arg-names)
|
||||
(assert-types= ,@lambda-list)
|
||||
,@body)))
|
||||
|
||||
|
||||
(define-syntax (define-module module-name (:imports ()) :exports . body)
|
||||
(let ((module-prefix (concat-strings (symbol->string module-name) "::")))
|
||||
(eval `(begin @(map (lambda (x) `(,import ,x)) imports) @body))
|
||||
(eval `(begin ,@(map (lambda (x) `(,import ,x)) imports) ,@body))
|
||||
(pair 'begin
|
||||
(map (lambda (orig-export-name)
|
||||
(let ((export-name (string->symbol
|
||||
@@ -189,8 +189,8 @@ condition is false."
|
||||
(let ((generic-map-name (string->symbol
|
||||
(concat-strings "generic-" (symbol->string fun-name) "-map"))))
|
||||
(unless (bound? generic-map-name)
|
||||
(define generic-map-name (create-hash-map)))
|
||||
(hm/set! generic-map-name types (eval `(,lambda ,names @body)))
|
||||
(define generic-map-name (hash-map)))
|
||||
(hm/set! generic-map-name types (eval `(,lambda ,names ,@body)))
|
||||
;; now check if the generic procedure already exists
|
||||
(if (bound? fun-name)
|
||||
(let ((exisiting-fun (eval fun-name)))
|
||||
|
||||
Binary file not shown.
@@ -1,12 +1,12 @@
|
||||
|
||||
(define hm1 (create-hash-map))
|
||||
(define hm1 (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))
|
||||
(define hm2 (hash-map))
|
||||
(hm/set! hm2 'yes :yes)
|
||||
(hm/set! hm2 :yes 'yes)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
(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))
|
||||
(define hm3 (hash-map))
|
||||
(hm/set! hm3 + 'plus)
|
||||
(hm/set! hm3 - 'minus)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user