Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Totaly newbie trying to learn LISP at uni

2 views
Skip to first unread message

arien

unread,
Oct 10, 2002, 1:12:21 AM10/10/02
to
In lisp if you want y to be true before proceeding, you write it like
this:

(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.

Ilya

unread,
Oct 10, 2002, 1:23:40 AM10/10/02
to
arien wrote:
> In lisp if you want y to be true before proceeding, you write it like
> this:
>
> (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) (......)))

(cond ((not y) ...))

Ilya

Adam Warner

unread,
Oct 10, 2002, 1:49:39 AM10/10/02
to
Hi Ilya,

Or:

(unless y ...)

Regards,
Adam

Kenny Tilton

unread,
Oct 10, 2002, 11:10:18 AM10/10/02
to

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

arien

unread,
Oct 10, 2002, 11:36:54 AM10/10/02
to
In article <3DA59996...@nyc.rr.com>, kti...@nyc.rr.com says...

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 :-)

Kenny Tilton

unread,
Oct 10, 2002, 11:49:35 AM10/10/02
to

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


Joe Marshall

unread,
Oct 10, 2002, 11:54:09 AM10/10/02
to
arien <spamme...@getlost.invalid> writes:

> 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

Christophe Rhodes

unread,
Oct 10, 2002, 12:01:44 PM10/10/02
to
Kenny Tilton <kti...@nyc.rr.com> writes:

> 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)

Jeremy Yallop

unread,
Oct 10, 2002, 12:11:57 PM10/10/02
to
Kenny Tilton wrote:
> Speaking of which, not sure have heard of a convincing tie-break on
> "-p" versus "p" as the suffix for predicate.

The convention is described in CLTL2, chapter 6:

http://www.supelec.fr/docs/cltl/clm/node69.html

Jeremy.

Erik Naggum

unread,
Oct 10, 2002, 6:14:09 PM10/10/02
to
* arien <spamme...@getlost.invalid>

| So how do you rearrange the code so that you instead do a test for y is
| not true?

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.

arien

unread,
Oct 10, 2002, 8:08:37 PM10/10/02
to
In article <65wath...@ccs.neu.edu>, j...@ccs.neu.edu says...

ah, now that makes some sort of sense, I think :-)

--
Mel

Gareth McCaughan

unread,
Oct 11, 2002, 8:20:18 PM10/11/02
to
"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?

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

Thomas A. Russ

unread,
Oct 11, 2002, 7:49:08 PM10/11/02
to
arien <spamme...@getlost.invalid> writes:
>
> 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?

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

Erik Naggum

unread,
Oct 11, 2002, 11:34:56 PM10/11/02
to
* t...@sevak.isi.edu (Thomas A. Russ)

| (null x) is equivalent to (and (symbolp x) (listp x))
| (null x) is equivalent to (and (listp x) (not (consp x)))

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ด.

0 new messages