Null value in Mit-Scheme?

15.8k Views Asked by At

Can anyone tell me what is the null value representation in mit-scheme? In the SICP book, it should be "nil" but it doesn't work. Thanks.

4

There are 4 best solutions below

2
On BEST ANSWER

'() should work. Basically, nil in scheme is the empty list, so quoting an empty list gives you nil.

0
On

(list ) '() and () can represent null. for example,

(define (transpose mat) (accumulate-n cons () mat))

or substitute () with '() or (list ).

0
On

I use MIT/GNU Scheme microcode 15.3, () and '() all works. (as you said, nil and null doesn't work).

1 ]=> ()

;Value: ()

1 ]=> '()

;Value: ()

1 ]=> (cons 1 ())

;Value 2: (1)

1 ]=> (cons 1 '())

;Value 3: (1)
0
On

There is the history. visit http://web.archive.org/web/20070808004043/http://wiki.wordaligned.org/sicp/published/FrequentlyAskedQuestions

Original(broken): http://wiki.wordaligned.org/sicp/published/FrequentlyAskedQuestions


Text from the above FAQ (in case of Internet Archive breakage):

Why isn’t “nil” working?

The quick answer is: nil is no longer part of Scheme, use '() instead. The long answer follows…

Early examples in Chapter 2 use nil as a list terminator, but when these examples are run using (e.g.) MIT Scheme, you get:

;Unbound variable: nil

Similarly, using () or null in place of nil may work on some implementations, but neither is portable. The Wizard Book addresses the issue in this footnote

It’s remarkable how much energy in the standardization of Lisp dialects has been dissipated in arguments that are literally over nothing: Should nil be an ordinary name? Should the value of nil be a symbol? Should it be a list? Should it be a pair? In Scheme, nil is an ordinary name, which we use in this section as a variable whose value is the end-of-list marker (just as true is an ordinary variable that has a true value). Other dialects of Lisp, including Common Lisp, treat nil as a special symbol. The authors of this book, who have endured too many language standardization brawls, would like to avoid the entire issue. Once we have introduced quotation in section 2.3, we will denote the empty list as ‘() and dispense with the variable nil entirely.

Since this was written, nil has been excised from the Scheme standard—but the bottom line holds: use ‘(), not nil. In an email to the accu-sicp list, Mike notes:

It’s a troublesome thing, this nil/null/'() business. Scheme48 and scm don't define null, and guile defines it but as a procedure akin to common lisp's null (to go with its nil which behaves like cl's nil, which itself is distinct from '()—maybe this had something to do with fsf's plans to re-do emacs in guile). I think the best bet is to replace the authors’ use of nil with ‘().

[Copied with just a touch of typographical clean up, to better match Markdown and usual ASCII input into the languages/implementations in question.]