(cond (y (... code here ...)))
So how do you rearrange the code so that you instead do a test for y is
not true? I tried this:
(cond ((y null) (......)))
but this doesn't seem to work. I've tried a few different variations,
and I don't know if my problem is this, or somewhere else in my code.
TIA
--
Mel
Please post reply to newsgroup. Reply address isn't valid.
(cond ((not y) ...))
Ilya
Or:
(unless y ...)
Regards,
Adam
This reminded me of the agony with which I choose each time I code such
a thing between (not y) and the alternative (null y), so I checked the
hyperspec...
http://www.lispworks.com/reference/HyperSpec/Front/index.htm
"not is intended to be used to invert the `truth value' of a boolean (or
generalized boolean) whereas null is intended to be used to test for the
empty list. Operationally, not and null compute the same result; which
to use is a matter of style."
OK, so not is indeed preferred in that the OP was looking to test for
"not true", not the empty list. neat.
kenny
clinisys
Thanks for that. Our text seems to support using 'null'. I still can't
get my head around the difference between (null y) and (nil y).
Perhaps you could enlighten me there too?
--
Mel - who has only seen Java, and suddenly in the darkness, LISP rises
up over the horizon in a spectrum of colours. This wouldn't be such a
bad thing except for the colourblindness :-)
arien wrote:
>
> Thanks for that. Our text seems to support using 'null'. I still can't
> get my head around the difference between (null y) and (nil y).
>
> Perhaps you could enlighten me there too?
>
Good one, right?
The Venerables and/or BetterHistorians may have the answer. I suspect an
early naming deviant from later conventions but too late to change.
Like, if the terms were nil and nilp there would be no confusion. But if
"null" got picked before the "p" thing reached Golden Convention status
(and you gotta think the keyword for testing the empty list was needed
pretty early in the game) then it would be hard to roll back, breaking
so much code. Along the same lines we have atom, where atomp would be
more conventional.
Speaking of which, not sure have heard of a convincing tie-break on
"-p" versus "p" as the suffix for predicate.
kenny
clinisys
> Thanks for that. Our text seems to support using 'null'. I still can't
> get my head around the difference between (null y) and (nil y).
>
> Perhaps you could enlighten me there too?
NULL is a function of one argument
NIL is not a function
(null y) => true if y is '(), false otherwise
(nil y) => ERROR, NIL isn't a function
as an analogy:
(zerop y) => true if y is zero
(0 y) => ERROR, 0 isn't a function
> Speaking of which, not sure have heard of a convincing tie-break on
> "-p" versus "p" as the suffix for predicate.
ONEWORDP but SEVERAL-JOINED-WITH-HYPHENS-P... though sadly DEFSTRUCT
gets this wrong :-/
Christophe
--
http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge)
The convention is described in CLTL2, chapter 6:
http://www.supelec.fr/docs/cltl/clm/node69.html
Jeremy.
A test whether y is not true is a test whether not-y is true. We use
(not y) to produce not-y.
When you get more experienced with Common Lisp, you may find that you
need a short-hand for this if you do it a lot. If you have a Unicode or
even a ISO 8859-1 system, you can write the support code to get 流 to
produce (not y) the same way 'y produces (quote y) in the standard syntax
because this is such a frequent thing to want, just like #'foo produces
(function foo) which you also need quite frequently in Common Lisp.
--
Erik Naggum, Oslo, Norway
Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
ah, now that makes some sort of sense, I think :-)
--
Mel
> Thanks for that. Our text seems to support using 'null'. I still can't
> get my head around the difference between (null y) and (nil y).
>
> Perhaps you could enlighten me there too?
Your fundamental problem here comes, I think, from the
fact that although "nil" is a noun and "null" an adjective,
Java uses "null" as a noun. (Possibly because its designers
were scared of making anything in it sound like Lisp?
They certainly weren't unaware of Lisp!)
"Null" is the adjective that describes "nil".
--
Gareth McCaughan Gareth.M...@pobox.com
.sig under construc
Well, NIL is a symbol and also the empty list. NULL is a function and
tests for the empty list. Thus (NULL NIL) => T. NIL is not a function
at all so trying to apply it will generate an error. I don't know if
this will help, but:
(null nil) => t
(null t) => nil
(symbolp nil) => t
(symbolp ()) => t
(symbolp '()) => t
(listp nil) => t
(consp nil) => nil
(listp '(a b)) => t
(consp '(a b)) => t
(null '(a b)) => nil
(null x) is equivalent to (and (symbolp x) (listp x))
(null x) is equivalent to (and (listp x) (not (consp x)))
--
Thomas A. Russ, USC/Information Sciences Institute t...@isi.edu
It makes more sense to regard (null x) as equivalent to (typep x 'null).
Note that `nullด is a system class the only object of which type is `nilด.