help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (list) and '(list)


From: David Kastrup
Subject: Re: (list) and '(list)
Date: Fri, 27 Apr 2007 12:39:00 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.98 (gnu/linux)

Kai Grossjohann <kai@emptydomain.de> writes:

> Perhaps what you want is to write a special form yourself?  That
> can't be done in a strict sense, but you can use macros to
> approximate the effect.
>
> For example, to reverse the condition of `if' (proof of concept only,
> not production code):
>
> (defmacro ifnot (test no yes)
>   (if (not test) no yes))
>
> Does that help?

You are confusing `defmacro' with `defsubst'.  What you wrote above
will have the effect of _compiling_ to no if the _unevaluated_ first
argument is anything but nil, and to yes if it is nil.

That is:
(ifnot blurb "x" "y")
will (at compile time already) be resolved to "x", regardless whether
blurb is currently (or at run time) nil.  In fact, the _value_ of
blurb is _never_ consulted.  To compile to "y", use one of the
following:
(ifnot nil "x" "y")
(ifnot () "x" "y")
What will _not_ work is
(ifnot '() "x" "y")
Because then test will be set to (quote nil) when the test is done,
which is not nil, even though it evaluates to nil.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum


reply via email to

[Prev in Thread] Current Thread [Next in Thread]