Python syntax in Lisp and Scheme
Pascal Costanza
costanza at web.de
Thu Oct 9 05:13:44 EDT 2003
Andrew Dalke wrote:
> Pascal Costanza:
>
>>He provides more information at http://www.paulgraham.com/icad.html
>
> I have run across his pages before, and have a hard time
> symphathizing with his view of things. For example, the start of
> the icad essay mentions that Lisp is already "kind of unusual"
> compared to C because it includes a full interpreter. But
> effectively all Python programs shipped include a full interpreter
> as well, and many give access to that interpreter, so I don't
> see what's unusual about it. Ditto for Tcl apps. Even some of
> my command-line perl apps included a way to pass in perl
> code on the command line, as for a search filter.
I guess this reflects his experiences when he has learned Lisp in the
beginning of the 80's (AFAIK).
Yes, scripting languages have caught up in this regard. (However, note
that Common Lisp also includes a full compiler at runtime.)
> The phrase "they had hard-headed engineering reasons for
> making the syntax look so strange." reminds me of the statement
> "better first rate salespeople and second rate engineers than
> second rate salespeople and first rate engineers" (and better
> first rate both). That's saying *nothing* about the languages;
> it's saying that his viewpoint seems to exclude the idea that
> there are hard-headed non-engineering reasons for doing things."
No, that's not a logical conclusion.
> Consider one of those "hard-headed engineering reasons", at
> http://www.paulgraham.com/popular.html
>
> It has sometimes been said that Lisp should use first and
> rest instead of car and cdr, because it would make programs
> easier to read. Maybe for the first couple hours. But a hacker
> can learn quickly enough that car means the first element
> of a list and cdr means the rest. Using first and rest means
> 50% more typing. And they are also different lengths, meaning
> that the arguments won't line up when they're called,
>
> That to me is a solid case of post hoc ergo proper. The
> words "1st" and "rst" are equally as short and easier to
> memorize. And if terseness were very important, then
> what about using "." for car and ">" for cdr? No, the reason
> is that that's the way it started and it will stay that way
> because of network effects -- is that a solid engineering
> reason? Well, it depends, but my guess is that he wouldn't
> weight strongly the impact of social behaviours as part of
> good engineering. I do.
As you have already noted in another note, car and cdr can be composed.
cadr is the second element, caddr is the third, cadddr is the fourth,
and so on. cddr is the rest after the second element, cdddr is the rest
after the third element, and so on. Other abbreviations I have used
relatively often are caar, cdar, cadar.
These abbreviations seem strange to a Lisp outsider, but they are very
convenient, and they are easy to read once you have gotten used to them.
You don't actually "count" the elements in your head every time you see
these operators, but they rather become patterns that you recognize in
one go.
I don't know how this could be done with 1st, rst or hd, tl respectively.
Of course, Common Lisp also provides first, second, third, and so on, up
to ninth, and rest. It also provides nth with (nth 0 l) = (car l), (nth
1 l) = (cadr l), and so on and (nthcdr 0 l) = l, (nthcdr 1 l) = (cdr l),
(nthcdr 2 l) = (cddr l) and so on.
Pick your choice. "There is not only one way to do it." (tm)
The learning curve is steeper, but in the long run you become much more
productive.
Pascal
--
Pascal Costanza University of Bonn
mailto:costanza at web.de Institute of Computer Science III
http://www.pascalcostanza.de Römerstr. 164, D-53117 Bonn (Germany)
More information about the Python-list
mailing list