[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Sat, 28 Jul 2012 11:04:55 -0700
On Fri, Jul 27, 2012 at 10:50 AM, Achim Gratz <address@hidden> wrote:
> Pascal J. Bourguignon writes:
>> C-h f eval-when-compile RET
>> Like `progn', but evaluates the body at compile time if you're compiling.
>> Thus, the result of the body appears to the compiler as a quoted
>> In interpreted code, this is entirely equivalent to `progn'.
>> What more can I add?
> I read that. It doesn't seem to work that way or has some strings
> attached that aren't obvious to me from the documentation.
>> The above source will evaluate, when you compile the file:
>> (defvar unquoted-t "true")
>> '(defvar quoted-nil "false")
> No. They will evaluate to
> (defvar quoted-nil "false")
> The unquoted variant was only there to check if maybe there's another
> `(quote …)´ snuck in. I expected the defvar form to compile, but it
You missed this part:
Thus, the result of the body appears to the compiler as a quoted constant.
So they really evaluate to:
'(defvar quoted-nil "false")
Which of course does nothing, so the compiler optimizes it away.
You know what you could do?
'(defvar quoted-t "true")
'(defvar quoted-nil "false")))
That'll compile to:
'(defvar quoted-nil "false"))
Gehm's Corollary to Clark's Law: Any technology distinguishable from
magic is insufficiently advanced.