> > I have a need to learn enough scheme to read it and write a few functions. > I came across dotted pair notation. I am trying to grok it in terms of the > only Lisp I know, Clojure. Does dotted pair notation in Scheme compare to > form in Clojure, and if so, how? >
As David notes, dotted-pairs are not allowed in Clojure because they allow for improper lists, which would break many of the nice HOFs we like to use (map, filter, etc). Dotted-pairs exist in Scheme because of the structure of the original cons-cell, essentially a structure with two pointers, car and cdr. In a proper list, car will point to some value and cdr will point to either another cons-cell or nil. Now suppose you want to encode a list of properties, i.e. key-value pairs. You could make a proper list where each car points to a pair, which would be another cons-cell since that's all we have to work with. This will work very nicely for small-ish property lists. But how should we encode the properties themselves? We could make a proper list of length two, where the first car points to the key and the second points to the value, but that's kinda wasteful. We're using two whole cons-cells when we really just need one: car points to the key and cdr to the value. And there you have it, the historical justification for dotted-pairs. They were very useful to save memory, perhaps other reasons as well, but this is the main one I know. Of course with the abundance of RAM on modern machines, this is much less of a concern, so Clojure enforces proper lists to increase safety :) Hope this was somewhat understandable, I'm too lazy to try to draw ASCII box-and-pointer diagrams right now.. Eric -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
