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