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

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

Started reading Ch. 2.  Interesting stuff!  I thought the summary of Ch 1
was great - a lot of stuff boiled down to one paragraph.  I'm going to go
through this one in a little more detail.  I have an idea about how to
solve ex. 2.16, and I might try it later.

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: