3 ms·
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 for
by wvenable 16y ago
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.
- brlewis 16y agoPlease show me your group-beginning and group-ending code.
- wvenable 16y agoHere'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.
- shaunxcode 16y agoI'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");
- wvenable 16y agoNice. 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?
- shaunxcode 16y agoYeah 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 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 http://commonphp.blogspot.com is where I write about it.
- dugmartin 16y agoThis uses my company's PHP templating engine (which is open source and available at http://tierratemplates.com 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.