

Lisphp is a Lisp dialect written in PHP. - jperras
http://github.com/lunant/lisphp

======
leftnode
Happy to see PHP be taken more seriously around here. Trust me, we're not all
moronic programmers using register globals, magic quotes, and other
abominations originally available in PHP.

This is a pretty cool project.

~~~
mattew
I think PHP suffers from some of the same issues that VB6 suffered from in
terms of inexperienced programmers. With VB6, someone who was not as much of a
programmer as we all are could write themselves into a massive mess. I have
found when writing PHP code if you are careful, you can build things with
decent design patterns and consistency. Sure, its not as clean as a lot of
languages, but it sure is easier for me to figure out what is going on with
PHP code someone else wrote compared to Perl or Ruby code.

~~~
jacquesm
This single biggest issue I've found when working with PHP for larger projects
is that even if you are a disciplined programmer you get to the point where
the includes will eat up your performance and your memory requirements will
become larger. See drupal as an example of this.

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.

~~~
asnyder
That's what autoload is for. It's been around since PHP 5.0.
<http://php.net/manual/en/language.oop5.autoload.php> and allows you to
require the necessary files or classes only when you need them. Seems like
they solved this problem to me.

~~~
gaoshan
I use frameworks (Zend, CodeIgniter) for all PHP projects except protoyping
HTML templates (like, when knocking out a quick page with placeholder data and
functionality to show a client). The hate poured on PHP for functionality that
I have never, ever used (read pretty much any "PHP sucks because..." post and
notice that the majority of the complaints are for things that real PHP
developers are well aware of and effortlessly deal with) gets tiresome to hear
about. Use it following some basic, current, best practices and it is fast,
easy and perfectly fine for developing with.

------
dahlia
I'm the author of this, I made the web REPL also.

<http://dahlia.ruree.net/try-lisphp/>

Well, of course, it uses a sandbox environment.

~~~
mahmud
From a quick look, you managed to get one thing right, even though it baffles
even respected language implementers: a proper stack trace on error. Most
people who write a HLL interpreter in another HLL tend to cheat and implement
a half-baked source to source translator.

[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.]

~~~
KirinDave
> Most people who write a HLL interpreter in another HLL tend to cheat and
> implement a half-baked source to source translator.

Is this a jab at the Lisp tradition of compiled sublanguages?

~~~
jimbokun
Bad stack traces is certainly one of the major complaints against Clojure.

~~~
KirinDave
They seem fine to me.

Do you want to see “bad” stack traces? Try Erlang. There is a language with
truly obtuse stack traces.

~~~
eru
And the very concept of strack traces does not even make too much sense in
e.g. Haskell. (Though it can be made to work, with some cleverness.)

------
andrewvc
This is analagous to McDonalds serving duck confit (and it actually tasting
kind of good).

------
jacquesm
Minor nitpick, the cdr implementation is (out of need, as far as I can see)
terribly slow for larger datasets, it uses array_slice($this->getArrayCopy(),
1) .

~~~
dahlia
I implemented cdr just to respect a Lisp tradition. Lisphp's Lisphp_List type
isn't a linked list but a subtype of ArrayObject, which supports random
access. So instead of doing:

    
    
      (car (cdr (cdr (cdr list))))
    

you should just do:

    
    
      (at list 3)

~~~
sedachv
Since Lisphp is a new dialect, you don't need to worry about backward-
compatibility. You should get rid of car/cdr entirely. There is no inherent
reason for using linked lists for anything - even s-expressions. For example,
no one has ever complained about the lack of car/cdr in Parenscript (although
to be fair, Parenscript is not homoiconic, just a translator from CL to JS).
Having a good backquote-comma templating syntax is more valuable.

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.

~~~
jacquesm
I think it's actually quite neat that it tries to stay close to the lisp code
that you see in examples and books about lisp.

~~~
sedachv
What's the point of sacrificing something like platform integration for
car/cdr? Anyone who is going to want to use Lisphp for real work is not going
to have a problem writing their code to use arrays. Anyone who thinks that
car/cdr is more valuable than platform integration is not going to use Lisphp
for real work. And everyone else will come by and say "Lisphp has those weird
car/cdr and it can't even work with PHP libraries without glue code, Lisp is a
toy."

------
shaunxcode
I think I need to change the name of my repository now. I am now the author of
"phlisp" <http://github.com/shaunxcode/phlisp> to avoid confusion. hah. It is
cool to see a different approach to the same problem! I am going more for
source -> source, quasiquote macros, TCO, some arc-esque syntactic sugar etc.
and back to php4 compat. Definitely a kick in the ass to release it now as I
have stalled since april due to "work".

------
arnorhs
This is maybe not so useless but definitely awesome!

At least this would solve the whole "which server should I use for lisp"
problem...

~~~
jacquesm
That was exactly my thought, the lisp deployment problem can be checked off
the list. This also significantly lowers the barrier to entry for people that
want to try lisp.

He seems to have done (much) more than a half baked job of it judging by the
rest of the page.

~~~
jules
There is lisp and there is lisp. The libraries and the speed do matter. While
this is an interesting project it's not comparable to SBCL, Racket or Clojure.

~~~
jimbokun
"The libraries and the speed do matter."

Does PHP lack for good libraries? That was the trick Clojure used with Java to
get bootstrapped.

~~~
jules
> Does PHP lack for libraries?

No.

> Does PHP lack for good libraries?

Yes. PHP's libraries are one of the ugliest and non lispy in existence :(

~~~
jacquesm
Since they were not made with 'lisp' or anything 'lispy' in mind that should
come as no surprise.

PHP is about as declarative as you get, assignments are the norm, not the
exception and side-effects are how just about everything is done. It's not
exactly elegant, but it fills a niche and apparently fills it quite well.

Though python is catching up, and even if it isn't quite as easy to deploy a
large scale python web application as it is to deploy PHP the difference is
getting smaller all the time.

------
mcs
It's kind of funny that people see PHP related to anything other than serving
websites and they cringe.

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.

~~~
jimbokun
I just finished reading "Javascript the Good Parts" recently. It's probably
also the case for PHP that if you pretend that certain parts of the language
just don't exist, you end up with a pretty good language. (I have never
programmed anything in PHP.)

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.

~~~
gtani
[http://www.amazon.com/PHP-Good-Parts-Delivering-
Best/dp/0596...](http://www.amazon.com/PHP-Good-Parts-Delivering-
Best/dp/0596804377/)

------
jcw
Has anyone tried running code with this yet? This results in errors:

    
    
      <?php
      require_once('Lisphp.php');
      $env = Lisphp_Environment::full();
      $program = new Lisphp_Program("(echo 1)");
      $program->execute($env);
      ?>

~~~
dahlia
Try this:

    
    
      $env['echo'] = new Lisphp_Runtime_PHPFunction(create_function('', '
          $args = func_get_args();
          foreach ($args as $arg) echo $arg;
      '));
    

after:

    
    
      $env = Lisphp_Environment::full();

~~~
jcw
Thanks! From the 'try lisphp' page, I assumed that echo was built in.

------
oneofamillion
A related project is clpython. I think lisphp can be a funny way for people
using php to learn some dialect of Lisp. But in the end, there is glue with C
code for example FFI to get speed.

------
asimjalis
Similar to Lisp2Perl

<http://www.hhdave.pwp.blueyonder.co.uk/>

Which implements Lisp on Perl.

~~~
stcredzero
Counter-intuitively, it's often easier to implement a more powerful, more
elegant language in a less powerful one than the other way around. Often, good
language design is correlated with elegant syntax, which contributes to this.

~~~
eru
Maybe. Though it is relatively easy to implement an ancient BASIC in Haskell.
The other way around is harder.

------
prodigal_erik
I hope he finds workarounds for some of PHP's more serious defects, like "pass
by value or maybe reference" semantics, no user-defined types as indices (even
most primitive types get silently mangled), and == being just blatantly wrong.
Part of what makes a language pleasant to use is that it doesn't keep
surprising you--stuff you'd expect to work, does.

------
dahlia
I made the mailing list (Google Groups) which is the place for discussion
about Lisphp:

lisphp@googlegroups.com

<http://groups.google.com/group/lisphp>

Join us if you are interested in this project!

------
c00p3r
Let me guess - _\\(get_global_var "HTTP_SERVER", $MyServer, $ENV\\)_

------
c00p3r
<http://news.ycombinator.com/item?id=1467067>

------
c00p3r
Smartguys should write a lisp dialect for erlang VM. ^_^

------
mkramlich
ugly language meets pretty language

have a few drinks

nine months later, baby arrives and uploaded to GitHub! :)

