3 ms·
As for cons... It seems to me that cons is a rather obsolete construct, referring to a long obsolesced hardware feature. I can't get too unhappy about someone t
by Xurinos 15y ago
As for cons... It seems to me that cons is a rather obsolete construct, referring to a long obsolesced hardware feature. I can't get too unhappy about someone trying to make it more immediately useful in a modern context.
Actually, it neatly fits the place of the concept of a "Pair" or "two-value tuple". SICP suggests that it serves the most basic function of data structures, that it can glue any two values together; from CONS can all (?) other data structures arise. It has little to do with lists other than the fact that most sources show you how to use CONS to construct a singly-linked list (a CS 101 data structure), and there is some built-in support for this basic approach. However, Common Lisp also provides built-in support for using CONS to construct arbitrary trees of data.
The notions that CONS is only for pushing an element onto a list, that CAR is equivalent to FIRST or HEAD, and that CDR is equivalent to REST or TAIL are a misunderstanding of its power -- one that I accidentally made in the past. Rename it to "CONSTRUCT-PAIR", and it makes more sense.
I have to admit when I first glanced at NewLisp, thinking it was a kind of modern revision of Lisp, this incorrect pigeon-holing was one of my big turn-offs and tends to lend credence to statements like "NewLisp repeats the design mistakes of ancient Lisps that were fixed in the newer Lisps". All that said, it's great to see people dabbling with their own experimental languages; it is a great learning experience for the developers.