Null scheme
The converse holds as well; a version of fold written in Elisp can fold over a ' -terminated list, as made by Scheme. On a low level, the bit representations for f , t , nil , and ' are made in such a way that they differ by only one bit, and so a test for, for example, f -or- nil may be made very efficiently.
However, in Elisp, ' , f , and nil are all equal though not eq. These choices facilitate interoperability between Elisp and Scheme code, but they are not perfect.
Some code that is correct standard Scheme is not correct in the presence of a second false and null value. The long answer follows…. Early examples in Chapter 2 use nil as a list terminator, but when these examples are run using e. MIT Scheme, you get:. 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.
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. In an email to the accu-sicp list, Mike notes:. 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.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Lists are often used to represent function calls, where the list consists of a function name followed by its arguments.
However, lists can also used to represent arbitrary collections of data. Symbols are treated as variables, and to evaluate them, their bindings are looked up in the current environment. For lists, the first element specifies the function. The remaining elements of the list specify the arguments.
Evaluate the first element in the current environment to find the function, and evaluate each of the arguments in the current environment, and call the function on these values.
Because Scheme will treat the atom elmer as a variable name and try to look for its binding, which it won't find. We therefore need to "quote" the names elmer and fudd , which means that we want scheme to treat them literally.
Scheme provides syntax for doing this. The evaluation for quoted objects is that a quoted object evalutes to itself. When the reader reads ' a b it translates this into quote a b , which is then passed onto the evaluator.
When the evaluator sees an expression of the form quote s-expr it just returns s-expr. The quote mark is an example of what is called "syntactic sugar. You might be wondering why the null pointer object is called "the empty list"; I'll explain that later. Given the way lists are usually used in Scheme, it turns out to make perfect sense. You can write the empty list as a literal in your programs as '. That is, the expression ' returns the empty list null pointer ,.
0コメント