15 ms·
> Modern Lisps now evaluate (car nil) and (cdr nil) to nil. Scheme doesn't. Taking the CAR or CDR of nil is an error.
by lisper 2y ago
> Modern Lisps now evaluate (car nil) and (cdr nil) to nil.
Scheme doesn't. Taking the CAR or CDR of nil is an error.
- anthk 2y agoElisp and CL do.
- susam 2y agoDoes Scheme even have NIL in the sense that other Lisps like CL or Elisp have? I mean in Common Lisp, we have: CL-USER> (symbolp nil) T CL-USER> (atom nil) T CL-USER> (listp nil) T Similar results in Emacs Lisp. But in MIT Scheme, we get: 1 ]=> nil ;Unbound variable: nil Of course, we can use () or (define nil ()) to illustrate your point. For example: 1 ]=> (car ()) ;The object (), passed as the first argument to car, is not the correct type. But when I said NIL earlier, I really meant the symbol NIL that evaluates to NIL and is both a LIST and ATOM. But otherwise, yes, I understand your point and agree with it.
- dokyun 2y agoI don't believe so, standardly. Guile scheme added the value `#nil' which is equivalent to NIL and distinct from #f and the empty list, but this was done in order to support Emacs Lisp.
- lisper 2y ago> Does Scheme even have NIL in the sense that other Lisps like CL or Elisp have? No. It has an empty list, which is a singleton atomic value whose type is not shared with any other object, and it has a boolean false value, which is distinct from the empty list. A user can create a symbol named NIL, but that symbol has no characteristics that distinguish it from any other symbol. You can, of course, bind NIL to either the empty list or boolean false (or any other value) but it can only have one value at a time (per thread).
- blenderob 2y ago> No. It has an empty list If there is no nil in scheme, what did you mean when you said that taking car or dr of nil is an error in scheme?
- lisper 2y agoYou need to read more carefully. The claim was not that there is no NIL in Scheme, the claim was that Scheme does not have a "NIL in the sense that other Lisps like CL or Elisp have". There is a NIL is Scheme, but it's just a symbol like any other with no privileged status. Also, in colloquial use, the word "nil" is often taken to be a synonym for "the empty list" even when talking about Scheme.
- pmarreck 2y agoI'm not a LISPer but this just seems more correct to me, since stricter is usually more correct. Ruby (not a lisp but bear with me) started to do this more correctly IMHO where a nil would start throwing errors if you tried to do things with it BUT it would still be equivalent to false in boolean checks.
- lisper 2y agoIt depends on what you are trying to optimize for. There is a benefit to punning the empty list and boolean false. It lets you shorten (not (null x)) to just x, and that is a common enough idiom that it actually makes a difference in real code. And there is a benefit to being able to say or type "nil" instead of "the empty list" because "nil" is shorter. But yeah, for modern production code, I agree that stricter is better, all else being equal.
- pmarreck 2y agoI love that I started out saying "I'm not a LISPer" and someone whose username is literally "lisper" responded. >..< Is there a purely functional Lisp that compiles to machine code yet?
- lisper 2y agoThat depends on what you mean by "purely functional Lisp". You can write purely functional code in any Lisp, and you can compile any Lisp to machine language, and this has been true for decades. AFAIK there is no Lisp that enforces purely functional programming, but it's easy to build one if that's what you want.
- pmarreck 2y agoThat is what I want. Turns out that LFE (Lisp-Flavored Erlang) exists… Wait, doesn’t Clojure have this, to a large degree at least?
- pmarreck 2y ago