[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dotted lists



>>>>> "Ken" == Ken Tilton <71460.744@compuserve.com> writes:

    Ken> Beginner Q...  StCLtLp30 suggests (a b c . d) is OK, and MCL
    Ken> accepts it, but hits the Listener if I try to take its
    Ken> (length).

    Ken> Q1: This is a feature, yes? (I gather MCL is pretty solid.)

a dotted list is not a "true" (i.e. nil terminated) list. (a b c . d) is
a dotted list, but is not an acceptable argument to length as you
discovered. ANSI defines length to only accept proper sequences, and
signal an error of type type-error otherwise. 

ANSI defines proper lists as those which are NOT dotted and NOT
circular. Many of the list and sequence functions will not work on
improper lists.

list-length, on the other hand will handle circular (but not dotted)
lists, and return NIL on circular lists.

    Ken> Q2: *If* it is a feature, isn't it inconsistent for MCL to
    Ken> *accept* a badly-formed (Q2.1: Is it?) quoted list.

no, it's not badly formed, it's dotted.

    Ken> I note that (a b c.d) works as advertised.

That's because |c.d| is a single atom. You didn't use the dot operator,
you constructed a token with a dot in the name.

    Ken> I *do* see Steele mentions "In MacLisp, the dot...need not be
    Ken> surrounded by white space." The MCL behavior suggests to me
    Ken> "_must_ not be surrounded by white space" is the rule here.

    Ken> Q3: (curiosity only) I gather MacLisp is unrelated to the
    Ken> Macintosh. Is MCL related to/derived from MacLisp in any way?

Maclisp is an ancestor of Common Lisp, but the name is derived from
project MAC, not the Macintosh. It predates the Macintosh by well over
10 years.

    Ken> I am freaking out over how magnificent CL is, but I *do* want
    Ken> to understand behind the scenes stuff, so Q2 above is very
    Ken> interesting to me.

    Ken> Hang on...maybe the inspector will let me at the cons cells. I
    Ken> would like to see what exactly MCL cobbled together.

    Ken> Ken Tilton Missing Link Software

Note that if you want some additional support for dotted lists, you can
download CL-LIB from the ALU (association of lisp user) pages, at
http://www.cs.rochester.edu/u/miller/alu.html

The file cl-extensions.lisp include definitions of all the MAP?x functions
that will handle dotted (or undotted) lists.
(e.g. MAPCAR-DOTTED-LIST, MAPL-DOTTED-LIST etc).

Hope this helps,
--
Brad Miller                    miller@cs.rochester.edu
Computer Science Dept.         http://www.cs.rochester.edu/u/miller/
University of Rochester        716-275-1118 (v) 461-2018 (f)
Rochester, NY 14627-0226