Lists Home |
Date Index |
Lisp provides loops and conditionals as expressions. They are incredibly
useful, since loops and conditionals can return values and be nested inside
other expressions. All the C based languages (including Java) have
conditional expressions, written as (condition ? result-if-true :
result-if-false). In Lisp, one can write things like:
(let ((x (loop for i from 1 to (length my-list) as item in my-list
collect (+ i item))) ...)
which creates a new list made by adding the index of the item in the
original list to the item for each item and binds the local variable x to
the new list.
Conditionals can be written as (if condition result-if-true
result-if-false), and use it like this:
(some-function (if (> x 0) (f x) (g (- x)) ...)
Common Lisp may also be the origin of the names of the 'every' and 'some'
expressions in XPath 2.0.
Most Lisp programmers are unhappy to lose conditional and iterative
expressions when they switch to other languages. In general, the statement
vs. expression distinction in languages is often more of a nuisance than a
help, particularly if you are trying to write a program to translate one
language into another.
----- Original Message -----
From: "Jeni Tennison" <firstname.lastname@example.org>
To: "Jonathan Robie" <email@example.com>
Sent: Thursday, May 09, 2002 4:44 PM
Subject: Re: [xml-dev] XPath 2.0 - how much of XQuery should it include?
> XPath 2.0 incorporates a number of *statements* that are already
> provided by XSLT 2.0. The for "expression" and the if "expression"
> would be classed as statements in any other language. XPath 2.0 also
> replicates other functionality that's already supported in XSLT:
> sorting, for example, and variable assignment (though obviously XPath
> 2.0 can only carry out variable assignment in limited contexts,
> something that in my opinion undermines the idea that for expressions
> can solve all the problems of sequence construction in XSLT 2.0).
> Obviously XQuery needs this -- it has to have statements because it
> isn't embedded in something that does -- but XPath 2.0 doesn't (or
> wouldn't if XSLT 2.0 was adjusted to enable it to create sequences of
> atomic values, something that I believe is entirely feasible).