add letrec.
This commit is contained in:
parent
1da953b6ab
commit
1584bb8701
8
mes.c
8
mes.c
|
@ -165,6 +165,13 @@ set_cdr_x (scm *x, scm *e)
|
|||
{
|
||||
assert (x->type == PAIR);
|
||||
x->cdr = e;
|
||||
return &scm_unspecified;
|
||||
}
|
||||
|
||||
scm *
|
||||
set_x (scm *x, scm *e, scm *a)
|
||||
{
|
||||
return set_cdr_x (assoc (x, a), e);
|
||||
}
|
||||
|
||||
scm *
|
||||
|
@ -477,6 +484,7 @@ lookup (char *x, scm *a)
|
|||
if (!strcmp (x, scm_lambda.name)) return &scm_lambda;
|
||||
if (!strcmp (x, scm_label.name)) return &scm_label;
|
||||
if (!strcmp (x, scm_nil.name)) return &scm_nil;
|
||||
if (!strcmp (x, scm_symbol_set_x.name)) return &scm_symbol_set_x;
|
||||
|
||||
#if QUASIQUOTE
|
||||
if (*x == '`') return &scm_symbol_quasiquote;
|
||||
|
|
17
scm.mes
17
scm.mes
|
@ -75,3 +75,20 @@
|
|||
(#t
|
||||
(cond ((pair? else) (car else))
|
||||
(#t *unspecified*)))))
|
||||
|
||||
(define (unspecified-bindings bindings params)
|
||||
(cond ((null? bindings) params)
|
||||
(#t (unspecified-bindings
|
||||
(cdr bindings)
|
||||
(append params (cons (cons (caar bindings) '(*unspecified*)) '()))))))
|
||||
|
||||
(define (letrec-setters bindings setters)
|
||||
(cond ((null? bindings) setters)
|
||||
(#t (letrec-setters (cdr bindings)
|
||||
(append setters
|
||||
(cons (cons 'set! (car bindings)) '()))))))
|
||||
|
||||
(define-macro (letrec bindings . body)
|
||||
(cons 'let (cons (unspecified-bindings bindings '())
|
||||
(append (letrec-setters bindings '())
|
||||
body))) )
|
||||
|
|
Loading…
Reference in a new issue