Subject: Re: Embedding Lisp in arbitrary text files (or: "Lisp server pages")
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 11 Jan 2009 05:20:05 -0600
Newsgroups: comp.lang.lisp
Message-ID: <baednVrSA7B4SPTUnZ2dnUVZ_hKdnZ2d@speakeasy.net>
WalterGR  <waltergr@gmail.com> wrote:
+---------------
| Right.  But since HTML/XML/XHTML are "just" s-exprs, the approaches
| you outline are absolutely equivalent in expressiveness to the *SP
| approaches.
+---------------

"Expressiveness", perhaps. But I've always found the *SP approaches
to be *very* ugly & error-prone when it comes to embedding control
structures such as loops, e.g.:

   <html>
   <body>
   Here we have a sequence of numbers:
   <br>
   <?php $i=1; while($i<=5) { ?>
     This is number <?php echo $i; ?>
     <br>
   <?php $i++; }
   ?>
   </body>
   </html>

The fact that you can leave PHP-land (or ASP land, etc.) with a
left bracket unclosed is simply horrifying to me! Now try doing
this with a doubly-nested loop with additional IF-THEN-ELSEs in
them, and things get *really* messy!

And if you want to avoid that, then you have to construct (almost)
*all* of your output *inside* the *SP language [using "Response.Write"
in ASP/VBScript or "echo" in PHP], which makes it equivalent in style
[except worse, IMHO] to the HTOUT/CL-WHO-style methods -- and you're
right back to quoting all your body text & and escaping quotes in text!

    <?php
      echo "<html><body>Here we have a sequence of numbers:<br>";
      $i=1; 
      while($i<=5) {
	echo "This is number " . $i . "<br />";
	$i++;
      }
      echo "</body></html>";
     ?>

+---------------
| What do the CL-WHO-esque approaches really buy someone?
+---------------

1. No such dangling brackets as above.

2. Can do everything in a natural Lisp environment, e.g.:

     (with-html-output (s *standard-output*)
       (:html
	 (:body
	   "Here we have a sequence of numbers:" :br
	   (dotimes (i 5)
	     (htm "This is number" i :br)))))

3. Have *all* of Common Lisp available.

+---------------
| > But if you absolutely insist on having a "raw text" format that uses
| > angle brackets [snip]
| 
| s/angle brackets/parenthesis/g and back to you.  :)
+---------------

I don't "insist", myself, I just find HTOUT (or CL-WHO, etc.) more
convenient when writing sizable pages with lots of control flow.
E.g., a *small* example:

    http://rpw3.org/hacks/lisp/appsrv-demo.lhp

[I would show you much bigger examples with lots of tables
with variously-formatted outputs from SQL database queries,
but unfortunately they're part of clients' proprietary apps.]


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607