views:

416

answers:

4

Greenspun's Tenth Rule of Programming is a common aphorism in computer programming and especially programming language circles. It states:

Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.

The questions are,

  1. Would you consider this to be true of Perl interpreter? Only objective arguments please (e.g. which features of Common Lisp are implemented within the interpreter)

  2. Independently, does there exist a Lisp (or at least a n ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp) implemented entirely in Perl?

+18  A: 

You might like the preface (as well as the rest of the book) for Mark Jason Dominus's Higher-Order Perl, whose subject is essentially your question. He says:

If you pick up a good book about Lisp, there will be a section that describes Lisp's good features. For example, the book Paradigms of Artificial Intelligence Programming, by Peter Norvig, includes a section titled What Makes Lisp Different? that describes seven features of Lisp. Perl shares six of these features; ...

Mark has many other things to say about Lisp and Perl

So, Perl is already Lisp, practically, but I'd say neither slow nor half. One of the things that Mark points about about the difference between Perl and Lisp, however, is that Perlers deal with unstructured strings (in general) while Lispers deal with structured data whenever possible. Perl can do that, but Perlers tend not to do that.

brian d foy
+1 for your answer generally but I can't agree that Perl is not slow. You can argue that Perl is fast enough for some tasks. You can argue that Perl is sometimes surprisingly fast for some unexpected tasks. But Perl is slow compared to modern Lisp implementations. For example try write regular expression engine in Perl (don't use Perl internal one) and compare it with http://weitz.de/cl-ppcre/ which is written in Lisp. Try compare object creations, destruction, method access overhead to some Common Lisp implementation. Try compare function call overhead. Well, you haven't chance in most cases.
Hynek -Pichi- Vychodil
That perl might be relatively slow to Lisp doesn't mean that perl isn't fast. I've certainly worked with much slower implementations of languages.
brian d foy
@brian d foy: *... Perl is Lisp ..., but I'd say neither slow nor half (implementation of Lisp).* It is what you wrote. I have done too much work in Perl then I can agree with this. I have seen good (mine :-)) Perl code outperforming bad Java (and of course bad Perl :-)) code. I have seen good Perl code outperforming bad usage of RDBMS (MySQL in usage where MySQL usually outperforms competitors). But anyway I would not say that Perl is not slow with same sentence with Lisp mentioned.
Hynek -Pichi- Vychodil
Again, I have the same response. I wouldn't say it, but I did and I still do.
brian d foy
Perl may have a little more than half, as do many other modern dynamic languages. What continues to differentiate Lisp is that Lisp programs are Lisp data structures (in a much deeper sense than the fact that most dynamic languages eval a string).
Zak
+2  A: 

The problem with that aphorism is that it isn't saying very much. Common Lisp is so complicated and general-purpose that it implements almost any feature a programming language could have. Thus, all it's really saying is that any sufficiently complicated system contains half of all possible features.

And yes, Perl is sufficiently complicated.

Gabe
@Gabe - yet, Lisp embodies some unique identifying features (first order fucntions etc...) that can be catalogued and measured as a functional spec. What I was looking for was a frmalized list of such features, which was indeed mentioned in brian's answer.
DVK
My point was that just about any feature of any system is already in Common Lisp, so asking what features X has in common with CL is like asking what "features does X have?"
Gabe
A: 

I'll leave aside the "slow" and "bug-ridden" parts, because they're basically cheap shots. Nothing prevents a deliberate, formally specified implementation of all of Common Lisp from being slow or bug ridden.

As for the rest, I think it tends to be true, but a lot of the reason for it being true is that Common Lisp provides quite a bit, and C provides so very little. Stuff as basic as hash tables, linked lists and expandable vectors are left up to the user to implement. All the memory management is manual, but you can automate it by doing ref-counting or even by adding a garbage collector. You can roll your own polymorphic OO by stashing function pointers in a struct somewhere and using it as a vtable. You may add an interpreter for a language to let you easily script your application, or ease interaction and testing at runtime.

That's pretty much half of Common Lisp; Perl really provides all of it and some other Lispy features to boot. But it doesn't really seem like that much of a big deal, because one thing that's changed in the 15+ years since Greenspun coined his Tenth Law (while skipping the other nine) is that lots of languages have added that same half of Common Lisp. Guy Steele said that about Java a few years later---it was dragging programmers halfway to Lisp.

Pillsy
+1  A: 
  1. See »What are the features that Perl shares with Lisp?«. The missing feature is true macros (this discounts source filters and Devel::Declare, which are a poor substitute from the POV of a lisper). Perl 6 has it.

  2. MJD provides a practical demonstration of the essential part of Lisp in Perl:
    Perl contains the λ-calculus

daxim