News for hackers. Stuff that matters.
Re:Practicality: PHP vs Lisp by brlewis on Friday July 02, 2010 @01:18PM (#1481674)
Say you want to connect to a database, fetch some data, and present it using HTML. Here's how it can be done using a DSL based on Scheme macros:

http://brl.codesimply.net/brl_4.html#SEC31

I can't forget to fetch the next row from the database. I can't forget to check that I'm at the end of the result set. Grouping the results is easy and straightforward. The statement and connection objects are automatically closed when the request is done. Compare that to PHP.

I'm getting better, but even today I feel a little irritated when someone says PHP was designed for simple web/database apps. I know what a language designed for simple web/db apps looks like, and PHP is not it.

Re:Practicality: PHP vs Lisp by wvenable on Friday July 02, 2010 @02:39PM (#1481910)
Have you even used PHP? There is nothing in your above statement (or linked code sample) that isn't done just as easily in PHP. Iterate over records using foreach, check. Closing database connections automatically (or out of scope), check. I could do grouping with about the same amount of code, too. PHP has it's ugly bits but it's not significantly different in capability from most other procedural/OO languages.
Re:Practicality: PHP vs Lisp by brlewis on Friday July 02, 2010 @02:57PM (#1481988)
Please show me your group-beginning and group-ending code.
Re:Practicality: PHP vs Lisp by dugmartin on Friday July 02, 2010 @07:09PM (#1482695)
This uses my company's PHP templating engine (which is open source and available at http://tierratemplates.com) and our internal CMS framework:

    // controller function
    public getcolors($request) {
      $db = CMS::GetDB();
      $request->favcolor = $db->transform($db->getRows("select * from favcolor order by color, name"), "collect", "color");
    }

    // and the template

    {@ favcolor ? 
      "<ul>"
      `<li><strong>{$key}</strong>: {$:implode(", ")}</li>`
      "</ul>" @}
the template uses a control structure called a conditerator (more info at the site). The controller uses a data transform to convert the set of rows into a hash of rows keyed on color.

I think that is more concise and reads better than the BRL example.

Re:Practicality: PHP vs Lisp by wvenable on Friday July 02, 2010 @03:21PM (#1482054)
Here's some possible PHP code to do what that Scheme code sample does (I've excluded the HTML for brevity):

    $result = $conn->execute('select * from favcolor order by color, name');
    while($row = $result->next()) {
        if ($result->groupBeginning('color')) {
            echo $row['color'].': '.$row['name'];
        } else {
            echo ', '.$row['name'];
        }
        if ($result->groupEnding('color')) echo "\n";
     }
     echo 'Count:'.$result->count();
I just came up that off the top of my head, but there's nothing impossible in there. Also, instead of field name for groupBeginning(), passing a closure would also be possible.
Re:Practicality: PHP vs Lisp by shaunxcode on Friday July 02, 2010 @04:35PM (#1482265)
I'll raise you my bleeding edge dsl:

  echo $conn->execute('select * from favcolor order by color, name')
            ->groupBy(L(val)->color)
            ->map(L(key)->wrap('<li><b>', '</b>')
                        ->append(
                          ': ',
                          L(val)->map(L(val)->name)->join(','),
                          '</li>'))
            ->join("\n");
Re:Practicality: PHP vs Lisp by wvenable on Friday July 02, 2010 @05:16PM (#1482396)
Nice. I've done something similar myself but I didn't take it exactly in the same direction. I leave much of grouping, wrapping, appending work to my own template engine layer. Is the source to your DSL available?
Re:Practicality: PHP vs Lisp by shaunxcode on Friday July 02, 2010 @05:42PM (#1482463)
Yeah I would normally never mix the templating/html w/ the data processing but I was trying to stick to the example but w/ one line hah. Right now it is part of my new web framework which is very much a work in progress but available on http://voltron.googlecode.com the relevant code for the Array dsl is under Model/Type/Array.php and FluentLambda.php and the constant declarations are in bootstrap.php - again total work in progress so things are not as clean as they should be just yet.

Also http://commonphp.blogspot.com is where I write about it.

Re:Practicality: PHP vs Lisp by jacquesm on Friday July 02, 2010 @01:55PM (#1481784)

  sql_apply("select id,somefield from sometable","applicator_function");
PHP is a programming language, it was not designed for 'simple web/database apps' any more than any other language, you can use the building blocks provided to create access at the level you require. But you can customize it so that it does become usable for 'simple web/database apps'.

The above is a short sample of how I'd do the thing you describe and I don't have to remember to fetch the next row from the table and I don't have to check that I'm at the end of the result set, grouping is as easy as SQL will make it and all cleanup is automatic.

Re:Practicality: PHP vs Lisp by btilly on Friday July 02, 2010 @08:26PM (#1482842)
PHP is a programming language, it was not designed for 'simple web/database apps' any more than any other language...

Um, yes it was. See http://en.wikipedia.org/wiki/PHP#History to verify that PHP started as a bunch of CGI binaries to serve some simple dynamic web pages. The database bit came later, but at the start it was explicitly designed for quick and dirty web pages.

Re:Practicality: PHP vs Lisp by jacquesm on Saturday July 03, 2010 @04:11AM (#1483500)
You can't seriously compare the state of PHP today with the first released version.

You could make such statements about every other mainstream language.

Re:Practicality: PHP vs Lisp by eru on Saturday July 03, 2010 @05:49AM (#1483592)
At least the Lisp guys have figured out how to write parsers and lexers by now. (They even grok lexical scoping.)

I guess we can't blame PHP for preserving the $ in front of variable-names with all the legacy code lying around. But the following should parse in a sane language:

  $width = getimagesize($filename)[0];
Adding support for this would not break legacy code. Nobody can tell me that naming all intermediate results like

  $sizes = getimagesize($img);
  $width = $sizes[0];
is such a preferable style, that the parser should enforce it.

By the way, this is how PHP pretends to support higher order functions:

  function cube($n) {return($n * $n * $n);}
  $a = array(1, 2, 3, 4, 5);
  $b = array_map("cube", $a);
Re:Practicality: PHP vs Lisp by btilly on Sunday July 04, 2010 @01:36PM (#1485998)
I never compared the state of PHP today with the first released version. I merely used the origins of PHP to argue that PHP was, indeed, more designed for simple web applications than most other general purpose programming languages.

And yes, you can make such statements about every other mainstream language. For instance Perl was more designed for text manipulation than most other general purpose programming languages. Java was more designed for multi-threading than most other general purpose languages. C was more designed for close to the machine programming than most other general purpose languages.

All of these things are true. All of these things still show in various ways. Yet every one of those is a general purpose language that can be used for anything you want.

Re:Practicality: PHP vs Lisp by brlewis on Friday July 02, 2010 @02:28PM (#1481882)
I want to abstract away the ways my app is like every other web app. I don't want to abstract away what's unique about it. If you abstract away everything, all languages are the same.
Re:Practicality: PHP vs Lisp by c141charlie on Saturday July 03, 2010 @01:59AM (#1483374)
The DSL snippet is every bit as verbose as the PHP code sample, yet somebody had to write the DSL in the first place. Not sure mission was accomplished. I think a better solution is offered by Mustache logic-less templates.
Re:Practicality: PHP vs Lisp by ninjac0der on Friday July 02, 2010 @02:49PM (#1481951)
This just looks like a massive step back from a MVC setup to me. How do proponents of using Lisp for web development handle interaction with designers?
Re:Practicality: PHP vs Lisp by brehaut on Friday July 02, 2010 @07:34PM (#1482741)
Regarding interaction with designers, I believe the answer is 'It Depends'.

As an example, in the Clojure space there are two libraries that are good exemplars of the ends of the spectrum: Hiccup and Enlive.

Hiccup (http://github.com/weavejester/hiccup) uses sexpressions to define the (ht|x)ml output. Effectively either the developer and designer roles are fused or the developer gets a design from the designer and encodes it into hiccup manually.

Enlive (http://github.com/cgrand/enlive) is (in overly simplistic terms) a selector driven substitution engine. You give it an HTML file for a template and some CSS selectors describing what to modify, alternatively you define a snippet in terms of some elements within the page. In this model the designers work is first class resource, and not modified by the developer.

This is exactly the same breadth of options as I've seen in just about any real language being used for development tools.

Re:Practicality: PHP vs Lisp by brlewis on Friday July 02, 2010 @02:56PM (#1481977)
This is just one style, not representative of all Lisp web development. You can have any style you want. With continuations you can even use a procedural style where your program describes a workflow of multiple pages.

(Whether MVC is the right style is a topic for another discussion.)

Re:Practicality: PHP vs Lisp by ninjac0der on Friday July 02, 2010 @03:01PM (#1482001)
Good too know. I would like to give Lisp a try, but I've only just being able to sell a php shop on migrating to python/django. Lisp is a near-impossible sell to every web dev shop I've worked in.