Live data from Hacker News

The empty list

tfeb.org

51–60 of 109 posts

Re: The empty list

#51
post #48

Earlier quoted context omitted.

>CL is moribund, not unlike Smalltalk, APL, and COBOL. If someone wants to do some hobby/small-scale but complex programming in LISP, what kind of dialect should they use? Scheme/Racket or something else?

Personally I do all my personal coding in CL but it's a matter of taste. Another word for "moribund" is "stable" and that can be a good thing. But it really is mostly personal preference. And you might want to add Clojure to your list of languages to consider. The reason I like CL is that I find it is a local optimum impedance match for my brain in language design space. But that is at least in part because I have be…

I'm afraid you're confusing 'stable' with 'stagnant'. (The dictionary suggests 'dying'... I won't go there ;))

Re: The empty list

#52
post #24

I've been trying to learn CL by using it to do AOC. As someone coming from mostly Python, there is a lot about it that confuses and, occasionally, frustrates me. Maybe I'm just missing something obvious but it doesn't seem like you can start with an empty list that you can repeatedly append to. The empty list is nil, and `(append nil foo)` seems to just yield `foo`, not `(list foo)`. So trying to append to that objec…

append concatenates lists so you'd need (append nil '(foo))

It actually leaves both its arguments unaltered and creates a new list. There's another function called nconc which does concatenate them, changing its first argument to the new list (unless its first argument is NIL).

Re: The empty list

#53

I've been trying to learn CL by using it to do AOC. As someone coming from mostly Python, there is a lot about it that confuses and, occasionally, frustrates me. Maybe I'm just missing something obvious but it doesn't seem like you can start with an empty list that you can repeatedly append to. The empty list is nil, and `(append nil foo)` seems to just yield `foo`, not `(list foo)`. So trying to append to that objec…

What is AOC? It’s hard to keep up with all the acronyms.

Re: The empty list

#54
The section on the `t` value could also have added that in the Common Lisp standard, there are a great many functions that returns a boolean value. When they return a true value, all that is required is that they return a value that isn't nil. This could be `t`, and often is, but is not required to be.

There are only a few forms that are required to return `t` for true, calls to the functions `not` and `null` being two of them. So, to coerce a true to `t`, one does `(not (not ))`.

Re: The empty list

#55
post #40

An annoying thing about `nil` is when it stomps a namespace in which you're using symbols, such as in a minilanguage, by being read as the nil value rather than as the symbol `nil`. Besides it being obvious, I actually ran into this in a real-world situation, with some super-rapid work on a dataset of only about 100 entries, where it turned out one user's real name had the initials N.I.L.

You should not have been reading that in a package that inherited from COMMON-LISP. Did you really want user names that happened to be COMMON-LISP symbols to collide?

Re: The empty list

#56
post #53

I've been trying to learn CL by using it to do AOC. As someone coming from mostly Python, there is a lot about it that confuses and, occasionally, frustrates me. Maybe I'm just missing something obvious but it doesn't seem like you can start with an empty list that you can repeatedly append to. The empty list is nil, and `(append nil foo)` seems to just yield `foo`, not `(list foo)`. So trying to append to that objec…

What is AOC? It’s hard to keep up with all the acronyms.

https://adventofcode.com/

Re: The empty list

#57
post #55
post #40

An annoying thing about `nil` is when it stomps a namespace in which you're using symbols, such as in a minilanguage, by being read as the nil value rather than as the symbol `nil`. Besides it being obvious, I actually ran into this in a real-world situation, with some super-rapid work on a dataset of only about 100 entries, where it turned out one user's real name had the initials N.I.L.

You should not have been reading that in a package that inherited from COMMON-LISP. Did you really want user names that happened to be COMMON-LISP symbols to collide?

That time was in Emacs Lisp. And it was very rapid-convenient to be using symbols.

When I moved to Scheme, I liked that it didn't have that particular collision. Though quasiquoting had some collisions unnecessarily (when they already had precedent of using the `#` character to introduce special values).

Re: The empty list

#58
post #51
post #48

Earlier quoted context omitted.

Personally I do all my personal coding in CL but it's a matter of taste. Another word for "moribund" is "stable" and that can be a good thing. But it really is mostly personal preference. And you might want to add Clojure to your list of languages to consider. The reason I like CL is that I find it is a local optimum impedance match for my brain in language design space. But that is at least in part because I have be…

I'm afraid you're confusing 'stable' with 'stagnant'. (The dictionary suggests 'dying'... I won't go there ;))

CL is not stagnant. SBCL and Quicklisp are still active, and Franz is still a going concern.

Re: The empty list

#59
post #37
post #33

Earlier quoted context omitted.

If NIL were a CONS, how would you distinguish between an empty list and a list of length one containing NIL?

The same way you do now: (NIL) would not answer true to NULL. And it would not be EQ to NIL.

If NIL were a CONS whose CAR is NIL and whose CDR is NIL, wouldn't NIL be the same as (CONS NIL NIL) = (NIL . NIL) = '(NIL)?

Re: The empty list

#60
post #39

Earlier quoted context omitted.

You are conflating implementation tricks with language semantics. In Lisp, NIL is always an atom, never a cons. Also, a dotted list is a nonempty list where the cdr of the last cons is not NIL. It is not a notational convention. A list (a b c) is not a dotted list, even if you write it as (a . (b . (c . nil))).

> You are conflating implementation tricks with language semantics. No, I'm not. > In Lisp, NIL is always an atom, never a cons. That depends on what you mean by "atom". If by "atom" you mean something that answers true to the ATOM predicate then yes, NIL is an atom. But if by "atom" you mean something that produces an error if you try to call CAR or CDR on it then no, NIL is not an atom, it is equal to (CONS NIL NIL…

But NIL is not equal to (CONS NIL NIL).

(CONS X NIL) = '(X), a list of length 1 containing X, so (CONS NIL NIL) = '(NIL), a list of length 1 containing NIL.

But NIL is a list of length 0, not a list of length 1.

The wart is that it should never have been the case that you could call CAR and CDR on NIL. But even though you can wartily call them on NIL, there is still clearly a very important distinction between NIL and (CONS (CAR NIL) (CDR NIL))!

Post reply on HN