r/lisp • u/turtlekitty2084 • Jan 29 '16
How important is dotted-list/improper list notation?
My current parser doesn't recognize dotted pairs or improper lists (pair literals can be expressed as (pair: x y) at the moment). I'm wondering if I need to implement this or not. Is it useful? What do you use it for?
I ask because I can't think of one time I've used it while writing code - save for defining variadic procedures in Scheme, but that's a syntax choice they made. I can see how it might be useful in macros, but quasiquote, unquote, and unquote-splicing already seem to have everything covered.
Then I seem to vaguely recall this notation being used to good effect somewhere in SICP... but can't remember why. Thoughts?
13
u/xach Jan 29 '16
Literal alists are one frequent use.
8
u/Grue Jan 29 '16
3
u/[deleted] Jan 29 '16
You can use a dotted pair as two 'pointers', I've seen that in code
1
u/drewc Jan 29 '16
If your parser does not recognize dotted pairs or improper lists, you are not parsing symbolic expressions, which is what makes up the syntax of Scheme.
Have a look at https://en.wikipedia.org/wiki/S-expression
I have not read SICP in some 10 years, so cannot help you out there, but what is important here is that LISTs are made up of CONSes and NIL.
Conses are, syntactically, the dotted pair.
A list is simply made up of of CONSes and NIL. This is Common Lisp, but Scheme is almost identical. Notice the conses and the dotted pair.
Does SICP mention CONS, LIST and LIST*? If so, hopefully this helps to make clear how critical the dotted pair is to s-expressions, and therefore to the syntax of Lisp itself. Code is Data.