Python syntax in Lisp and Scheme
Björn Lindberg
d95-bli at nada.kth.se
Thu Oct 9 05:53:46 EDT 2003
"Andrew Dalke" <adalke at mindspring.com> writes:
> > If you want some real world numbers on program length check here:
> > http://www.bagley.org/~doug/shootout/
>
> If I want some real world numbers on program length, I do it myself:
> http://pleac.sourceforge.net/
> I wrote most of the Python code there
>
> Still, since you insist, I went to the scorecard page and changed
> the weights to give LOC a multipler of 1 and the others a multiplier
> of 0. This is your definition of succinctness, yes? This table
> is sorted (I think) by least LOC to most.
<snip>
> So:
> - Why aren't you using Ocaml?
> - Why is Scheme at the top *and* bottom of the list?
> - Python is right up there with the Lisp/Scheme languages
> - ... and with Perl.
>
> Isn't that conclusion in contradiction to your statements
> that 1) "Perl is *far* more compact than Python is" and 2)
> the implicit one that Lisp is significantly more succinct than
> Python? (As you say, these are small projects .. but you did
> point out this site so implied it had some relevance.)
Apart from the usual problems with micro benchmarks, there are a few
things to consider regarding the LOC counts on that site:
* Declarations. Common Lisp gives the programmer the ability to
optimize a program by adding declarations to it. This is purely
optional, and something you normally don't do until you discover a
bottelneck in your code. For instance, it is possible to add type
declarations so that the compiler can generate more efficient
code. In a normal program, the declarations (if any) will
constitute an extremely small part of the program, but since the
micro benchmarks in the shootout are focused on speed of
execution, and they are so small, all of them contains a lot of
declarations, which will increase LOC.
* In many languages, any program can be written on a single
line. This goes for Lisp, ut also for C and other languages. This
means that the LOC count is also affected by formatting. For
instance, in the Ackermann's function benchmark, the Ackermann
function is written like this in the C code:
int Ack(int M, int N) { return(M ? (Ack(M-1,N ? Ack(M,(N-1)) : 1)) : N+1); }
That is, 1 LOC, although most people would probably write it in
anything between 5-10 lines.
* 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.
Björn
More information about the Python-list
mailing list