You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jason van Zyl <jv...@periapt.com> on 2000/09/09 20:39:28 UTC
Arithmetic
Hi,
How about using the #set directive for arithmetic
as well:
#set $foo = 1
#set $foo = $foo + 1
#set $velocity = $distance / $time
#set $value = (($foo / $bar) * $distance) % 5
#set $foo.Bar = ($x - $y) + $z
I have this parsing correctly, and I would
have to implement the same logic for:
#if (($x - $y) + $z > $a)
So it can be reused for setting values as
well.
Comments?
jvz.
--
Jason van Zyl
jvanzyl@periapt.com
Re: Arithmetic
Posted by Leon Messerschmidt <le...@opticode.co.za>.
Brilliant!
>Jason van Zyl wrote:
>
> Hi,
>
> How about using the #set directive for arithmetic
> as well:
>
> #set $foo = 1
> #set $foo = $foo + 1
> #set $velocity = $distance / $time
> #set $value = (($foo / $bar) * $distance) % 5
> #set $foo.Bar = ($x - $y) + $z
>
> I have this parsing correctly, and I would
> have to implement the same logic for:
>
> #if (($x - $y) + $z > $a)
>
> So it can be reused for setting values as
> well.
>
> Comments?
>
Re: Arithmetic
Posted by Travis Low <tr...@dawnstar.org>.
Perfect. Comments/questions:
- Do you require the parentheses, or will you observe arithmetic precedence and
allow:
#set $value = $foo + $bar * $baz
- To avoid opening a can of worms, I suggest throwing an exception when types
are mixed. Thus:
#if ($string && ($integer1 - $integer2))
would throw an exception. Otherwise, you have to decide how to treat "0" in
boolean expressions.
- Since you're moving ahead with development, should I write a spec, or should I
wait and document what you've done at the end?
Travis
Jason van Zyl wrote:
>
> Hi,
>
> How about using the #set directive for arithmetic
> as well:
>
> #set $foo = 1
> #set $foo = $foo + 1
> #set $velocity = $distance / $time
> #set $value = (($foo / $bar) * $distance) % 5
> #set $foo.Bar = ($x - $y) + $z
>
> I have this parsing correctly, and I would
> have to implement the same logic for:
>
> #if (($x - $y) + $z > $a)
>
> So it can be reused for setting values as
> well.
>
> Comments?