110 points · by jperras · 16y ago · 107 comments
This is a pretty cool project.
You can get around some of that by using a php accelerator but it would seem to me that something like that ought to be part of the basic distribution.
The LISP here is a neat project but I can't think of a practical niche. Sandboxed hosted scripting is praiseworthy, but most customers would want that in Javascript or PHP itself, not as a Lisp.
PHP already powers three of the top 10 websites. What was left to prove?
Where do you read that ? He's not making any suggestion of the kind, he's simply happy that PHP is not always scoffed on, and this piece of code is a really good example of what you can do when you use PHP properly. That comment could apply to plenty of other PHP projects. HN has a bit of a history of ridiculing PHP and the people who program in it.
> I don't agree.
With who ? Your strawman ?
The LISP here is a neat little stepping stone, just like almost any other 'language X implemented in Y' it is not currently meant as either a high performance solution or a production ready environment, just a neat little hack, easy to understand.
If you're in front of a river and someone builds you a rope bridge across you don't complain about the fact that it won't handle 6 lanes of highway traffic, you're just happy someone took the time and trouble to build it. If you don't want to use the bridge then fine, if you do then it's great.
What's left to prove is that there is a wrongness in the attitude towards certain classes of languages. I think PG is partly to blame for this with his 'blub' classification of programmers and languages. As though those that program in language X are somehow better than those that don't.
To tie LISP and PHP together in this way shows that that argument holds no water at all, and for some that may change their minds, which is good.
The naming of library functions alone can drive you bonkers. It's rare that I have to look up the names of functions in languages that I've used for a decade or more, with PHP it still happens with some regularity.
I know I could use an IDE to mitigate that but for some reason IDEs and me don't get along, with the exception of Borlands C Builder, which was really pretty good.
http://dahlia.ruree.net/try-lisphp/
Well, of course, it uses a sandbox environment.
[Edit:
Question: Why does it have T, NIL, #T and #F? what roles do these symbols play in the language; which ones are canonical truth values, which ones signify list termination, and which ones signify the empty value? This is the perennial Lisp question.]
Is this a jab at the Lisp tradition of compiled sublanguages?
A lame, wasteful little script to print out a TODO list ;-)
(defun map-print (item list)
(mapcar (lambda (x)
(format t "~a in ~a~%" item x)) list))
(defun permute (list)
(mapcar (lambda (x)
(map-print x list)) list))
(defun languages ()
(destructuring-bind (response headers body)
(trivial-http:http-get "http://mahmud.arablug.org/languages.txt")
(when (= response 200)
(loop for line = (read-line body nil nil)
while line
collecting line))))
(permute (languages))Respect!
For me that's the 'benchmark' of understanding a language, to be able to re-implement it.
edit: by the way, it's been more than two months, but there have been a lot of things done in that time that have nothing to do with programming.
http://dl.dropbox.com/u/2083231/essential_lisp_implementatio...
I would recommend these to someone who wants to implement a functional or a Lisp language, going with nothing but basic systems programming knowledge.
Recommend prerequisites are the first 2-3 chapters of SICP, some familiarity with classic compiler construction (dragon book would do, skip the lexical analysis and parsing parts though; you wont need much of that for Lisp if you retool and existing lexer. But focus on function calling and stack discipline, lexical scope and variable visibility, and maybe learn how an Algol dialect implements runtime heap-allocation) some exposure to C and assembly, and healthy curiosity.
A suggested order might be: Ghuloum, Wilson, Dybvig, the uncredited "lisp-implementation.pdf" paper, Gudeman, Kelsey, then Shao (Shao might make a whole lot more sense if you read one of Andrew Appel's compiler books and dip a tiny bit into ML.)
See http://research.microsoft.com/en-us/um/people/simonpj/papers... for some hints on writing a compiler for those (or just general amusement).
(car (cdr (cdr (cdr list))))
you should just do: (at list 3)The bigger problem is in code that consumes the lists item by item, every time an extra copy of the remainder of the list will be made, there it is much harder to work around this.
Very neat code by the way, thanks a ton for making this.
I'll be playing around with it for a bit, I've written a chunk of code for a small site a while ago in a 'functional' PHP style (as in, no assignments except at the highest level), I'll see if I can convert that project to your lisp dialect and get it to work.
You should even get rid of a custom type for Lisphp sequences and use PHP arrays directly. Ditto all other datatypes. Then if you use PHP's calling convention you should be able to call PHP code directly without needing USE and FROM, and more importantly PHP code can do the same to Lisphp with minimal pain. That way writing Lisphp libraries for others to use becomes viable.
Uh, constant-time insertions?
Of course, because of the whole shared hosting thing you'd have to fall back to a pure PHP implementation if the extension isn't loaded.
http://www.php.net/manual/en/class.spldoublylinkedlist.php
LispHP seems to use ArrayObject, though I'm not really sure how its performance is (googling indicates iteration is slow).
It's kind of moot because if speed were a huge concern, this might not be used in the first place, but just it would be interesting to see how far such a thing could be taken.
array_slice((array)$this, 1);
I'm not sure if this will be faster though. Is the source of the slowness getArrayCopy or array_slice itself?At least this would solve the whole "which server should I use for lisp" problem...
He seems to have done (much) more than a half baked job of it judging by the rest of the page.
It says a lot about about his work that I am very excited to hack on it for the rest of the day, and I am not easily impressed by toy Lisps :-)
Tip of the hat to the author for doing the right thing, imo.
Does PHP lack for good libraries? That was the trick Clojure used with Java to get bootstrapped.
As of 5.3 (and I won't say prior to that because even I don't believe it), PHP has become a nice utility language for just more than serving out wordpress.
Closures and the reference sweep GC level the playing field.
Building a Lisp on top of PHP strikes me as a vehicle for helping developers to adhere to the "good parts." I'm not sure whether that was the intent here, but it could turn out to be a useful side effect.
A note on the language itself:
It appears that you can choose any set of matching braces that you want anywhere in your program. I think this is the convention Scheme uses. Common Lisp reserves braces other than () for reader macros.
I personally, however, favor Clojure's approach of defining distinct behavior for each brace type. There are only three pairs of matched characters on the keyboard. It seems to me that this makes them too valuable to not leverage them as a core part of the language. Immediately knowing the meaning of a specific brace type makes it much easier to read someone else's code.
I have seen quiet a few PHP bashing comments recently that while true of older versions are much less true of 5.3, I mean there is still the same old nitpicks about the parameter orders and the amount of built in functions in the standard namespace but it is defiantly heading in the right direction.
An embedded lisp, even a slow and imperfect one is a nice stepping stone to have though.
It takes away two thirds of the trouble you have to go through when starting with a new language, environment and libraries.
<?php
require_once('Lisphp.php');
$env = Lisphp_Environment::full();
$program = new Lisphp_Program("(echo 1)");
$program->execute($env);
?>http://www.hhdave.pwp.blueyonder.co.uk/
Which implements Lisp on Perl.
lisphp@googlegroups.com
http://groups.google.com/group/lisphp
Join us if you are interested in this project!
have a few drinks
nine months later, baby arrives and uploaded to GitHub! :)