On Sun, 1 Oct 2000, Andy Armstrong wrote:

> First a short introduction: I've just joined the list today and started
> having a look at Velocity mainly because in a lot of ways it's close to
> a servlet based template engine (Takhini) that we've been developing in
> house (with a view to O/S release). I'll post a brief outline of that
> separately -- I'm hopeful that some of the work we've done may be useful
> here, and I'm quite prepared -- if we can see a way to migrate our
> existing Takhini based systems to Velocity -- to unfork and merge any
> useful bits of Takhini with Velocity.

That would be fantastic!
 
> I hope regulars here will forgive me for venturing an opinion on this
> subject. Normally I'd lurk for a while, but because we've covered this
> ground with Takhini I'm hopeful that I might have something to
> contribute immediately. Please feel free to put me in my place if I
> overstep the mark.

Oh, no worries :)

> Anyway, the first thing that occurs to me is that while having all
> directives pluggable seems in some ways very cool, I suspect that in
> practice once you've provided a full range of control structures (if,
> for, while, repeat, case, whatever) you're unlikely to want to plug in
> any additional directives with anything other than procedure call
> semantics (i.e. a name followed by some arguments). Pluggable syntax for
> control structures is a whole can of worms if you're going to have
> things like matching opening and closing keywords (#foreach .. #end)
> because you have to have pluggable syntax checking for them, including
> support for nested directives.

There are some directives that I would definitely like to leave
in the JavaCC grammar. The #set and #if/#elseif/#else directives
for example. But the #foreach directive works just fine as
a pluggable direcitive.

> Our approach with Takhini has been to hardwire the control structures
> (and things like assignments) into the language (we only currently have
> if/else and loop structures) and also make expression syntax hardwired,
> but make it possible for user code to extend the language by exposing
> functions (variadic) and variables/constants.

Some of the control structures are hard-wired in Velocity, all
the expression syntax as well.

> Next, a word about loops. Here's a little fragment of Takhini (Takhini
> substitutions are marked with '%'):
> 
>  %.name=['Fred','Jim','Albert']%   <!-- a list of names -->
>  %.age=[36,67,82]%                 <!-- a list of ages  -->
>  <table>
>     %{%            <!-- start of loop -->
>         <tr><td>%name%</td><td>%age%</td></tr>
>     %}%            <!-- end of loop -->
>  </table>
> 
> which translates into
> 
>  <table>
> 
>         <tr><td>Fred</td><td>36</td></tr>
>         <tr><td>Jim</td><td>67</td></tr>
>         <tr><td>Albert</td><td>82</td></tr>
> 
>  </table>
> 
> To make sense of that you need a little background. Firstly list values
> are vaguely magical in Takhini; for example most of the operators do
> special things with lists, so
> 
>   1 + 2                --> 3
>   "Hello, " + "World"  --> "Hello, World"
>   "Hello, " + ["World", "Chums"] --> ["Hello, World", "Hello, Chums"]
> 
> and loops have a special understanding of list objects, viz a loop will
> iterate once for each element in the largest list that is evaluated
> inside it, so the act of evaluating |name| and |age| inside the loop
> makes it iterate three times (if one list had four elements an empty
> string would have been provided for the missing element in the smaller
> string).
> 
> While at first glance this might look a little brain dead it actually
> makes a lot of sense in practice. One of the traditional problems with
> foreach style loops is that you can't iterate over the corresponding
> elements in multiple lists at one time. Also with foreach loops you
> don't typically have access to the loop index. In Takhini we have a 
> special variable ('$') that represents the current loop index. Enclosing
> loop indexes are $$ (for the innermost enclosing loop), $$$ for the one
> outside that and so on.

We have also discussed throwing in a special variable to
keep track of the loop index. Very easy to add.

> I'm going to post some more background about Takhini separately --
> hopefully we've got some bits and pieces that may be of interest.

Great! Send it on down the pipe :)

jvz.

-- 

Jason van Zyl
[EMAIL PROTECTED]

Reply via email to