Patrick (patrickwonders) wrote,
Patrick
patrickwonders

Preaching to people who were only in the choir because their parents made them do it....

So, last night, I started watching this video of Ken Tilton brain dumping about Lisp-ish things and the accompanying rant about why we should be developing apps instead of attending conferences.

Somewhere in defending Cells (which, in my opinion, speak for themselves), he mentioned the OpenLaszlo project. So, even though I should have been in bed an hour before, I started watching the webcast tutorial on OpenLaszlo. I was quite impressed with what I saw.

My group at work develops web app after web app in all kinds of different frameworks. So, I mentioned OpenLaszlo in our group Jabber room today. Someone asked me for my one paragraph impression. That sparked a bit of conversation in which I said that PHP, JSP, and LSP are working from a fundamentally flawed model wherein what you want to do is display data/information and what the language wants you to do is to craft HTML. All of that is beside the point here though.

Someone said, I've never heard of LSP. No surprise there. So, I explained, Think PHP but with the code in Lisp instead.

This, of course, got a bunch of groans from people who were soured on Lisp by some class they were forced to take taught by a bad teacher at a time when their little brains were not ready for Lisp.

I showed a little snippet for quick comparision. First, the PHP:

<?php
    foreach ( $list as $item ) {
?>
	<h2><?= $item->name ?></h2>
<?php
    }
?>

Then, the LSP (in the Jabber conversation, I used question marks where I should have used percent signs, but anyhow....):

<%
    (dolist (item list)
%>
	<h2><%= (slot-value item 'name) %></h2>
<%
    )
%>

Now, I think that braces do slightly better than parens in this whole interleaving business. Though, as I mentioned above, I think this whole interleaving business is fundamentally flawed. On the other hand, I think the (dolist ...) is much nicer than the foreach ( ... as ... ) business.

Someone complained Where are all of the 'cat'[sic] and 'cdr's? So, I expanded what (dolist ...) may expand into for reference (except, in the Jabber convo, I had messed up my end condtion for the (do ...) loop, forgetting it's an until rather than a while condition):

<%
(let ((#:g122 list))
    (do ((item (car #:g122) (cadr #:g122)))
	 ((null item))
%>
	<h2><%= (slot-value item 'name) %></h2>
<%
    ))
%>

This got the predictable That's the syntax that I've tried so hard to forget type comments. And, I couldn't let that go. This is a perfect example of the beauty of Lisp macros. How many years do you have this idiom in your Java:

java.util.Iterator it = list.iterator();
while ( it.hasNext() ) {
    MyItem item = (MyItem)it.next();
    java.lang.System.out.println( item.getName() );
}

...before the language police deigned to give you this ugly piece of syntactic molasses:

for ( MyItem item : list ) {
    java.lang.System.out.println( item.getName() );
}

...and you thanked them for it. In Lisp, you could have crafted (dolist ...) yourself before Java was even born.

If you're a C++ person, you might think the C preprocessor can bail you out of this mess. But, I'd be willing to bet that this four page article about writing a FOREACH macro for C++ contains at least a few things you didn't think of and a few things in the C++ standard that you would have bet were impossible.

Tags: lisp
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 4 comments