This threw me for a loop; up until this point I had assumed formal parameters were always enclosed in a list:
Note that things like (a . args)
and (a b . args)
are not really lists either. (a . args)
is a pair where the car
is the symbol a
and the cdr
is the symbol args
. (a b . args)
is a pair where the car
is the symbol a
and the cdr
is (a pair where the car
is the symbol b
and the cdr
is the symbol args
). It looks kind of like a list for a while, with the a
and b
and that, but as it doesn't end in null/the empty list it's not really a proper list. Structures like that are often called improper lists. If you wanna, you can read a little about the dotted-pair notation here, or somewhere else...
With (. args)
I'd maybe say something like "it is a pair where the cdr
is the symbol args
". Or maybe it'd come out like "a pair where the car
is and the cdr
is args
". Either way it wouldn't make a lot of sense, and, as Chris Jester-Young said, it's not really valid Scheme.
So. Things like (a b . args)
are just regular dotted pair notation for putting things that aren't null in the last cdr
. If the formal parameters-thing in Scheme can be one of those improper lists or a proper list or just a symbol, then the definition of the formal parameters-thing must be something like: a formal parameters-thing must be null, a symbol, or a pair where the car
is a symbol and the cdr
is a formal parameters-thing.
(Which I think is a kind of cool thing that makes for a rather elegant way of binding arguments to parameters. Like, you look at the formal parameters-thing, and if it's a symbol you bind the list of arguments to that and if it's a pair you bind the car
of the arguments to the cdr
of the formal parameters-thing and recur on cdr
of the formal paramters-thing/arguments (oh and if it's null you're like done or something). That strikes me as a little bit prettier than the Common Lisp way of "and if the symbol in car
is &rest
you bind the rest of the arguments to the symbol after that".)