tags:

views:

70

answers:

1

So I wrote this code. How do i get the x in the if statement to evaluate? at the moment, x always succeeds, and the if statement never fails.

(define expand
  (lambda (exp)
    (cond
     ((symbol? exp) exp)
     ((pair? exp)
      (case (car exp)
       ((and)
        (if (null? (cdr exp)) '(quote #t)
            (if (null? (cddr exp)) (cadr exp)
                (let ((x (cadr exp))
                      (thunk (lambda () (expand '(and ,(cddr exp))))))
                  (if x (thunk) 
                      `(quote ,x))))))
       (else exp)))
     (else exp))))
+1  A: 

Use eval, for example:

(if (eval x (null-environment 5))
    (thunk)
    `(quote ,x))
Greg Hewgill
Thanks, I had tried that. but it then gives me this error: The procedure #[compiled-procedure 1 ("global" #x5) #x3 #x412F2C] has been called with 1 argument' it requires exactly 2 arguments.
Chris
@Chris: Sorry, `eval` in scheme needs another parameter.
Greg Hewgill