Python syntax in Lisp and Scheme

Björn Lindberg d95-bli at nada.kth.se
Fri Oct 10 07:36:09 EDT 2003


"Andrew Dalke" <adalke at mindspring.com> writes:

> Björn Lindberg:
> > Apart from the usual problems with micro benchmarks, there are a few
> > things to consider regarding the LOC counts on that site:
> 
> I wasn't the one who pointed out those micro benchmarks.  Kenny
> Tilton pushed the idea that more concise code is better and that Lisp
> gives the most concise code, and that Perl is much more compact
> than Python.  He suggested I look at some comparisons, so I followed
> his suggestion and found that 1) the Lisp code there was not more
> succinct than Python and 2) neither was the Perl code.
> 
> >   * Declarations. Common Lisp gives the programmer the ability to
> >     optimize a program by adding declarations to it.
> 
> While OCaml, which has the smallest size, does type inferencing....

The good Lisp compilers do type inferencing too AFAIK, but since Lisp
is fully dynamic it is not always possible for the compiler to do full
type inference at compile time. Declarations help the compiler in this
respect.

<snip>

> >   * In many languages, any program can be written on a single
> >     line. This goes for Lisp, ut also for C and other languages.
> 
> Absolutely correct.  Both Alex Martellli and I tried to dissuade
> Kenny Tilton that LOC was the best measure of succinctness and
> appropriateness, and he objected.

I think in general there *is* a correlation between LOC and
succinctness, eg LOC(assembler) > LOC(C) > LOC(awk). It is probably
not a very strong correlation though, and it would probably be more
accurate for larger programs than small code snippets.

> >   * I don't think the LOC saving qualities of Lisp is made justice in
> >     micro benchmarks. The reason Lisp code is so much shorter than the
> >     equivalent code in other languages is because of the abstractive
> >     powers of Lisp, which means that the difference will be more
> >     visible the larger the program is.
> 
> Agreed.  I pointed out elsewhere that there has been no systematic
> study to show that Lisp code is indeed "so much shorter than the
> equivalent code in other languages" where "other languages" include
> Python, Perl, or Ruby.

It would be interesting to see such studies made.

> The closest is
>  http://www.ipd.uka.de/~prechelt/Biblio/
> where the example program, which was non-trivial in size
> took about 100LOC in Tcl/Rexx/python/perl and about 250LOC
> in Java/C/C++.

That is an interesting study, although there are some possible flaws
(eg no controlled selection of participants). The programming problem
in that study is far to small to meaningfully test any abstraction
capabilities in the language on the level of macros, OO or HOF
though.

<snip>

> In any case, it implies you need to get to some serious sized
> programs (1000 LOC? 10000LOC? A million?) before
> the advantages of Lisp appear to be significant.

I think that goes for any advantages due to abstraction capabilities
of macros, OO or HOF. The small program in the study above seems to
capture the scripting languages higher level compared to the
close-to-the-machine languages C & C++. (I have not read all of it
though.) To show advantages of the abstraction facilities we have been
discussing in this thread, I believe much larger programs are needed.


Björn




More information about the Python-list mailing list