guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheming over a PHP replacement


From: Per Bothner
Subject: Re: Scheming over a PHP replacement
Date: Tue, 01 Jan 2002 21:13:50 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20011221

Bruce Korb wrote:


However, one of the
points of PHP and AutoGen is that you specify most of the output
text directly and only insert expressions here and there where
you want to compute a text fragment.  The goal is to avoid being
balled up in working out program logic in order to emit several
variations on a block of text.


This is a popular approach (cfr. JSP and ASP), but I'm inclined to
think it is the wrong thing to do.  It make it easy to do a little
bit of calculation embedded inside a mostly static document.
However, it is more difficult to construct a complex document out
of simpler pieces, except by gluing strings together.  Typically
these are string literals, which means your language now has two
kinds of html literal text:  The outermost unquoted html, and the
inner html, nested first inside the logic "unquote" syntax and then
inside string quotes.  Worse, you are doing everything at the
string level, which means that if you want to processes some piece
of html though some filter function, that function has to *parse*
the text.  This is so painful that you normally don't want to do that.

For an alternate model, I suggest people take a look at XQuery
(http://www.w3.org/XML/Query).  The syntax is not lispish, but the
concepts can be mapped to a Lisp-style syntax easily enough (and
people have done similar things in Lisp).  The important concepts
are:
* There are expression forms for creating tree *values* (DOM).
These return objects, not strings.  The XQuery syntax has element
creation expressions, which look basically like XML, plus an
"unquote" syntax (curly braces) for nesting abritrary sub-expressions.
These sub-expressions can be functions that return other trees, etc.
(If you prefer, you could use a more concentional S-expr syntax
instead of XML syntax.)
* Expressions evaluate to simple values, node values, or sequences
of values.
* You can use "typeswitch" expressions or XPath patterns to
test node values.
* It is an *expression* side-effect-free language, where nodes are
first class values, that can be arguments and results of functions.
* It is both an xml query language (similar to sql) and an xml/html
generating language.

I've been working on a Free XQuerty implementation, using the Kawa
toolkit.  I'm tentayively calling it Qexo - see www.qexo.org.  I',
also mulling ideas for XQuery functionality with a more-or-less
Scheme syntax.  For example instead of XQuery's:
  <html:title id="{gen-id()}">A Title</jyml:title>
you might do:
   (html:title :id (gen-id) "A Title")
This uses some non-standard handling of the colon character to
indicate element and attribute constructors.

I've re-written my photo-gallery software (www.bothner.com/pics/)
to use Kawa-XQuery (alias Qexo), and it works quite well, even
in this early state.

--
        --Per Bothner
address@hidden   http://www.bothner.com/per/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]