mes.c: fix apply.
This commit is contained in:
parent
8c1a5f19da
commit
99762c07ca
11
mes.c
11
mes.c
|
@ -261,6 +261,7 @@ scm *caar (scm *x) {return car (car (x));}
|
|||
scm *cadr (scm *x) {return car (cdr (x));}
|
||||
scm *cdar (scm *x) {return cdr (car (x));}
|
||||
scm *cddr (scm *x) {return cdr (cdr (x));}
|
||||
scm *caaar (scm *x) {return car (car (car (x)));}
|
||||
scm *caadr (scm *x) {return car (car (cdr (x)));}
|
||||
scm *caddr (scm *x) {return car (cdr (cdr (x)));}
|
||||
scm *cdadr (scm *x) {return cdr (car (cdr (x)));}
|
||||
|
@ -334,7 +335,11 @@ apply_env (scm *fn, scm *x, scm *a)
|
|||
return apply_env (efn, x, a);
|
||||
}
|
||||
|
||||
scm *make_symbol (char const *s);
|
||||
scm *
|
||||
apply (scm *f, scm *x)
|
||||
{
|
||||
return apply_env (f, x, &scm_nil);
|
||||
}
|
||||
|
||||
scm *
|
||||
eval (scm *e, scm *a)
|
||||
|
@ -349,8 +354,8 @@ eval (scm *e, scm *a)
|
|||
scm *y = assq (e, a);
|
||||
if (y == &scm_f) {
|
||||
//return e;
|
||||
fprintf (stderr, "eval: no such symbol: %s\n", e->name);
|
||||
assert (!"unknown symbol");
|
||||
fprintf (stderr, "eval: unbound variable: %s\n", e->name);
|
||||
assert (!"unbound variable");
|
||||
}
|
||||
return cdr (y);
|
||||
}
|
||||
|
|
5
scm.mes
5
scm.mes
|
@ -109,9 +109,6 @@
|
|||
(if (= 0 n) '()
|
||||
(cons fill (loop (- n 1))))))))
|
||||
|
||||
(define (apply f args)
|
||||
(eval (cons f args) (current-module)))
|
||||
|
||||
(define-macro (defined? x)
|
||||
`(assq ,x (cddr (current-module))))
|
||||
|
||||
|
@ -121,6 +118,8 @@
|
|||
((and (pair? p) (eq? (car p) '*closure*)))
|
||||
(#t #f)))
|
||||
|
||||
(define integer? number?)
|
||||
|
||||
(define (assq-set! alist key val)
|
||||
(let ((entry (assq key alist)))
|
||||
(cond (entry (set-cdr! entry val)
|
||||
|
|
4
test.mes
4
test.mes
|
@ -244,6 +244,10 @@
|
|||
(let () (define *top-let-a* '*top-let-a*) #f)
|
||||
(pass-if "top let " (seq? (and (defined? '*top-let-a*) *top-let-a*) #f))
|
||||
|
||||
(pass-if "apply identity" (seq? (apply identity '(0)) 0))
|
||||
(pass-if "apply identity 2" (sequal? (apply identity '((0 1))) '(0 1)))
|
||||
(pass-if "apply append" (sequal? (apply append '((1 2) (3 4))) '(1 2 3 4)))
|
||||
|
||||
(newline)
|
||||
(display "passed: ") (display (car (result))) (newline)
|
||||
(display "failed: ") (display (cadr (result))) (newline)
|
||||
|
|
Loading…
Reference in a new issue