Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!mips!samsung!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: Partial evaluator sought Message-ID: <1991May10.055107.3185@Think.COM> Date: 10 May 91 05:51:07 GMT References: <13521@pasteur.Berkeley.EDU> Sender: news@Think.COM Reply-To: barmar@think.com Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 32 In article <13521@pasteur.Berkeley.EDU> boyland@sequoia.Berkeley.EDU (John B. Boyland) writes: >I'm looking for a general purpose Common Lisp partial evaluator; >a function which evaluates pure Lisp code if all values are known: The following should work in a Common Lisp that includes the condition system: (defun partial-eval (form) (handler-case () (values (eval form) t) ((or unbound-variable undefined-function) (values nil nil)))) Actually, I would suggest a macro form, so that the form would be evaluated in the correct lexical context: (defmacro partial-eval (&body body) `(handler-case () (progn .,body) ((or unbound-variable undefined-function) (values nil nil)))) This is similar to the definition of WITHOUT-ERRORS, except that it only catches certain errors. Another difference in this version is that it returns all the values of the body in the non-error case. If the application needs to distinguish the error from non-error case, then it must make sure that NIL, NIL is not a valid set of values of the body. -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar