[taos-glug] Re: nil vs '() using Guile and PLT Scheme

  • From: Jonathan Bartlett <johnnyb@xxxxxxxxxx>
  • To: taos-glug@xxxxxxxxxxxxx
  • Date: Thu, 14 Aug 2003 13:38:42 -0700 (PDT)

First of all, on PLT Scheme, be sure what version you are in.  I think you
want advanced mode. (MrEd doesn't matter either way).  Second of all, I
think nil may have gone away in the Scheme standard (R5RS uses it in an
example, but doesn't define it, I believe).  With standard scheme, use
'().

Of course, you can always (define nil '())

Also, on some schemes, false is '(), and on others #f is it's own entity.
I liked #f being '(), but I guess it makes sense for it not to be.  I
think R5RS is when #f got it's own entity, and '() was no longer false.

Jon

On Thu, 14 Aug 2003, Philip Ansteth wrote:

>
> I'm not sure why, but Guile wants you to use '() instead
> of nil.  For example, in the first version of scale-list
> in the section headed "Mapping of lists",  try '() instead of
> nil.
>
> Under PLT Scheme, nil doesn't work at all.  But '() does work.
>
>
> For example, using Guile,
>
> (define (scale-list items factor)
>   (if (null? items)
>       nil
>       (cons (* (car items) factor) (scale-list (cdr items) factor))))
>
> (scale-list (list 1 2 3 4 5) 10)
>
> yields
> (10 20 30 40 50 . nil)
>
> But, changing nil to '(), the following.
>
> (define (scale-list items factor)
>   (if (null? items)
>       '()
>       (cons (* (car items) factor) (scale-list (cdr items) factor))))
>
> (scale-list (list 1 2 3 4 5) 10)
>
> yields
> (10 20 30 40 50)
>
> Using PLT Scheme (= mzScheme?) on my Windows laptop, nil doesn't work at all,
> giving the message:  "reference to undefined identifier: nil"
>
>


Other related posts: