[newbie] evaluating a list as an expression
Posted: Sat Jan 17, 2009 8:23 pm
Hi all,
I'm trying to write a function that takes in a list (well, any expression actually), a list of symbols, and a list of values for those symbols, and then evaluates that list as an expression with those symbols assigned to those values. Perhaps my current attempt will explain this better than a description:
And then you could do something like:
This works fairly well, but gives me warnings about undefined variables most of the time (not in the above instance). As I'm new to common lisp, I was wondering if there is a better way of doing this, one that wouldn't produce warnings.
The following gives me warnings (though still returns the correct value):
where the warnings are:
Thanks!
I'm trying to write a function that takes in a list (well, any expression actually), a list of symbols, and a list of values for those symbols, and then evaluates that list as an expression with those symbols assigned to those values. Perhaps my current attempt will explain this better than a description:
Code: Select all
(defun eval-expr (expr symbols assignments)
(progv symbols assignments (eval expr)))
Code: Select all
* (let ((expr '(and p q)))
(eval-expr expr '(p q) '(t t)))
=> T
The following gives me warnings (though still returns the correct value):
Code: Select all
* (let ((expr '(or p q)))
(eval-expr expr '(p q) '(nil t)))
=> T
Code: Select all
; in: LAMBDA NIL
; (LET ((#:G758 P))
; (IF #:G758 #:G758 (OR Q)))
;
; caught WARNING:
; undefined variable: P
; (OR Q)
;
; caught WARNING:
; undefined variable: Q
;
; caught WARNING:
; These variables are undefined:
; P Q
;
; compilation unit finished
; caught 3 WARNING conditions