Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


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");


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?


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: