libera/#commonlisp - IRC Chatlog
Search
8:25:10
beach
This page says ALIST is an association list. And the glossary says that an association list is a list of conses.
8:27:01
beach
It gives two almost equivalent expressions, but they are equivalent only if NIL is a member of the association list. But then, it is not an association list, now is it?
8:28:32
beach
If I were to implement ASSOC, I would take the wording in the "Exceptional situations:" section to mean that if I detect that I don't have a proper list, or if I detect that an element is not a CONS cell, then I would signal an error.
8:29:08
beach
And that I don't have to search beyond a matching element to find out whether it is really an association list.
8:31:51
beach
And the error message hints that SBCL considers an association list to be a list of elements of type LIST, rather than (as the glossary says) a list of elements of type CONS.
8:40:36
Equill
I don't like it either, but this appears to be a case of duck-typing: both `(listp nil)` and `(atom nil)` return `t`, so the crucial test in this case is whether an element is considered a list, rather than whether it's (possibly _also_) some other type.
8:43:10
beach
I take the situation to be a "don't fail unless you have to" one. But this attitude is out of fashion, and nowadays we prefer "help the programmer as much as possible".
8:45:10
Equill
It's the part where it's a list but not a cons, that conflicts with my assumption that lists are by definition made of conses. That means there's something I didn't properly understand.
8:45:54
beach
Well, the empty list is a list, and the empty list is the same as NIL, so NIL must be a list.
8:46:26
beach
You are right that lists are "made of conses", but there could be zero conses in a list.
8:46:48
mariari
Equill: in ML, lists are defined as CONS or NIL, thus if you had a CONSP function, it should answer false for NIL. The same view can be said for CL, modulo improper lists
8:48:13
mariari
beach: fair, I was implicitly typing the cdr to be a LIST, which improper lists lets us say end it with 5
8:48:49
Equill
Defining a list as *zero or more* conses resolves that issue. Thanks for that insight.