From: arien
Subject: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <MPG.180fb03154b2d596989732@news.adl.ihug.com.au>
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.

From: Ilya
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <ao32st$268j$1@agate.berkeley.edu>
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
From: Kenny Tilton
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <3DA59996.9020908@nyc.rr.com>
Ilya wrote:
> 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) ...))

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
From: arien
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <MPG.18104293f5e0126a989737@news.adl.ihug.com.au>
In article <················@nyc.rr.com>, ·······@nyc.rr.com says...
> 
> 
> Ilya wrote:
> > 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) ...))
> 
> 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 :-)

Please post reply to newsgroup. Reply address isn't valid.
From: Joe Marshall
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <65wathlq.fsf@ccs.neu.edu>
arien <·············@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
From: arien
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <MPG.1810ba88f91c57898973e@news.adl.ihug.com.au>
In article <············@ccs.neu.edu>, ···@ccs.neu.edu says...
> arien <·············@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
> 

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

-- 
Mel

Please post reply to newsgroup. Reply address isn't valid.
From: Kenny Tilton
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <3DA5A2CB.8090605@nyc.rr.com>
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
From: Jeremy Yallop
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <ao48sd$jc8rn$1@ID-114079.news.dfncis.de>
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.
From: Christophe Rhodes
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <sqlm564713.fsf@lambda.jcn.srcf.net>
Kenny Tilton <·······@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)
From: Thomas A. Russ
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <ymi1y6wcz9n.fsf@sevak.isi.edu>
arien <·············@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          ···@isi.edu    
From: Erik Naggum
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <3243382496486911@naggum.no>
* ···@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�.

-- 
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.
From: Gareth McCaughan
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <slrnaqeqm2.1ef5.Gareth.McCaughan@g.local>
"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  ················@pobox.com
.sig under construc
From: Adam Warner
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <pan.2002.10.10.05.49.34.97700@consulting.net.nz>
Hi Ilya,

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

Or:

(unless y ...)

Regards,
Adam
From: Erik Naggum
Subject: Re: Totaly newbie trying to learn LISP at uni
Date: 
Message-ID: <3243276849563719@naggum.no>
* arien <·············@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 �y 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.