implement let loop.
This commit is contained in:
parent
b638d33e4b
commit
47fd339305
13
scm.mes
13
scm.mes
|
@ -62,10 +62,19 @@
|
||||||
(#t (split-values (cdr bindings)
|
(#t (split-values (cdr bindings)
|
||||||
(append values (cdar bindings) '())))))
|
(append values (cdar bindings) '())))))
|
||||||
|
|
||||||
(define-macro (let bindings . body)
|
(define-macro (simple-let bindings rest)
|
||||||
`((lambda ,(split-params bindings '()) ,@body)
|
`((lambda ,(split-params bindings '()) ,@rest)
|
||||||
,@(split-values bindings '())))
|
,@(split-values bindings '())))
|
||||||
|
|
||||||
|
(define-macro (let-loop label bindings rest)
|
||||||
|
`(let ((,label (lambda ,(split-params bindings '()) ,@rest)))
|
||||||
|
(,label ,@(split-values bindings '()))))
|
||||||
|
|
||||||
|
(define-macro (let bindings-or-label . rest)
|
||||||
|
`(if ,(symbol? bindings-or-label)
|
||||||
|
(let-loop ,bindings-or-label ,(car rest) ,(cdr rest))
|
||||||
|
(simple-let ,bindings-or-label ,rest)))
|
||||||
|
|
||||||
(define (expand-let* bindings body)
|
(define (expand-let* bindings body)
|
||||||
(cond ((null? bindings)
|
(cond ((null? bindings)
|
||||||
`((lambda () ,@body)))
|
`((lambda () ,@body)))
|
||||||
|
|
11
test.mes
11
test.mes
|
@ -81,6 +81,17 @@
|
||||||
(display 'let-dun)
|
(display 'let-dun)
|
||||||
(newline)
|
(newline)
|
||||||
|
|
||||||
|
(let loop ((lst '(3 2 1)))
|
||||||
|
(display "loop")
|
||||||
|
(newline)
|
||||||
|
(if (null? lst) (begin (display "dun") 'dun)
|
||||||
|
(begin
|
||||||
|
(display "looping: ")
|
||||||
|
(display (car lst))
|
||||||
|
(newline)
|
||||||
|
(loop (cdr lst)))))
|
||||||
|
(newline)
|
||||||
|
|
||||||
(define c 'b)
|
(define c 'b)
|
||||||
`(aa bb ,c)
|
`(aa bb ,c)
|
||||||
(display `(pp qq ,c))
|
(display `(pp qq ,c))
|
||||||
|
|
Loading…
Reference in a new issue