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.
'()
should work. Basically, nil in scheme is the empty list, so quoting an empty list gives you nil.
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):
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.]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With