Fixed TidBIT.
This commit is contained in:
+6
-4
@@ -49,11 +49,11 @@ The grammar:
|
|||||||
(define (binding-encountered bd id)
|
(define (binding-encountered bd id)
|
||||||
(lambda ([s : Symbol]) (if (symbol=? s id) 1 (add1 (bd s)))))
|
(lambda ([s : Symbol]) (if (symbol=? s id) 1 (add1 (bd s)))))
|
||||||
|
|
||||||
(: currycall : TIDBIT (Listof TIDBIT) BINDING-DEPTH -> CORE)
|
(: currycall : CORE (Listof TIDBIT) BINDING-DEPTH -> CORE)
|
||||||
(define (currycall body args bd)
|
(define (currycall body args bd)
|
||||||
(match args
|
(match args
|
||||||
['() (preprocess body bd)]
|
['() body]
|
||||||
[else (CCall (currycall body (rest args) bd) (preprocess (first args) bd))]))
|
[(cons f r) (currycall (CCall body (preprocess f bd)) r bd)]))
|
||||||
|
|
||||||
(: curryfn : (Listof Symbol) TIDBIT BINDING-DEPTH -> CORE)
|
(: curryfn : (Listof Symbol) TIDBIT BINDING-DEPTH -> CORE)
|
||||||
(define (curryfn params body bd)
|
(define (curryfn params body bd)
|
||||||
@@ -74,7 +74,7 @@ The grammar:
|
|||||||
[(With name value body) (CCall (CFun (preprocess body (binding-encountered bd name)))
|
[(With name value body) (CCall (CFun (preprocess body (binding-encountered bd name)))
|
||||||
(preprocess value bd))]
|
(preprocess value bd))]
|
||||||
[(Fun params body) (curryfn params body bd)]
|
[(Fun params body) (curryfn params body bd)]
|
||||||
[(Call body args) (currycall body args bd)]))
|
[(Call body args) (currycall (preprocess body bd) args bd)]))
|
||||||
|
|
||||||
(: parse-sexpr : Sexpr -> TIDBIT)
|
(: parse-sexpr : Sexpr -> TIDBIT)
|
||||||
; Parses Sexprs into TIDBITs.
|
; Parses Sexprs into TIDBITs.
|
||||||
@@ -156,6 +156,8 @@ The grammar:
|
|||||||
[else (error 'run "evaluation returned a non-number: ~s"
|
[else (error 'run "evaluation returned a non-number: ~s"
|
||||||
result)])))
|
result)])))
|
||||||
|
|
||||||
|
(test (run "{call {fun {x y z} {+ x {* y z}}} 1 2 3}") => 7)
|
||||||
|
|
||||||
(test (run "{{fun {x y z} {+ x {+ y z}}} of 1 2 3}") => 6)
|
(test (run "{{fun {x y z} {+ x {+ y z}}} of 1 2 3}") => 6)
|
||||||
|
|
||||||
(test (run "{{fun {x} {+ x 1}} of 4}")
|
(test (run "{{fun {x} {+ x 1}} of 4}")
|
||||||
|
|||||||
Reference in New Issue
Block a user