<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
What happens if you do <br>
<br>
(defun foo (x)<br>
(plus x 3))<br>
<br>
?<br>
<br>
Luís Oliveira wrote:
<blockquote
cite="mid:AANLkTimj5LsGMjhXE=7Uxy83uoZ98FxgHzTwn_q3i6-3@mail.gmail.com"
type="cite">
<pre wrap="">On Sun, Sep 5, 2010 at 9:59 PM, Scott L. Burson <a class="moz-txt-link-rfc2396E" href="mailto:Scott@sympoiesis.com"><Scott@sympoiesis.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">As tempting as it is to call EVAL for various purposes, the reality is that
correct uses of EVAL are quite rare. In fact, unless you're writing your
own read-eval-print loop of some kind, the best rule of thumb is that if
you're calling EVAL explicitly, you've made a mistake. I have trouble
coming up with any exceptions to this rule other than a REPL.
</pre>
</blockquote>
<pre wrap=""><!---->
One of the many tricks I've picked up from James Bielman (I hope he's
subscribed to this mailing list :-)) was using CONSTANTP and EVAL in
compiler macros. Here's a simple example:
(defun plus (x y)
(+ x y))
(define-compiler-macro plus (&whole form x y)
(if (and (constantp x) (constantp y))
(+ (eval x) (eval y))
form))
Execution examples:
(compiler-macroexpand-1 '(plus 1 1)) => 2
(compiler-macroexpand-1 '(plus '1 '1)) => 3
(compiler-macroexpand-1 '(plus (* 2 (/ 4 2)) (+ 3 2))) => 9
(defconstant +1+ 1)
(compiler-macroexpand-1 '(plus +1+ 2)) => 3
</pre>
</blockquote>
</body>
</html>