You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by SainTiss <sa...@arklinux.org> on 2004/03/15 20:43:25 UTC

does velocity support recursive macro's?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Does velocity support the use of recursive macro's?

I tried a simple one, which seems to work, but nevertheless I get an error 
message in the log:
VM #recursiveMacro: error : too few arguments to macro. Wanted 2 got 0

This seems to be a known problem, but now I'm wondering if I can just ignore 
this an carry on?

Also, from what I can see in my simple example, if I #set variables in such a 
macro, the value is overwritten in every recursive call, and not restored 
when the call returns to the above call. I guess that's normal, since macro's 
are just textual substitution, rather than the building of stackframes and 
the like, right?

But is there a way to get the behaviour of recursive functions (i.e. with a 
new context for each call)? Maybe using recursive #parse statements? 
(although I'm guessing that's just textual substitution too...)

Thanks,

Hans

- -- 
Ark Linux - Linux for the Masses (http://arklinux.org)

Capitalism: 
You don't have any cows. The bank will not lend you money to buy cows, 
because you don't have any cows to put up as collateral.

Representative Democracy:
You have two cows. Your neighbors pick someone to tell you who gets the milk. 

In a world without walls and fences, who needs windows and gates?

Hans Schippers
2LIC INF
UA 2003-2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAVgdgXlnUYIbmLOQRAnmdAJ93S+RdwZiyaaD6/K+9z2kvXjEsWQCgi0DM
eVs0S86osyh08fPcIikOwk4=
=l8JA
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: does velocity support recursive macro's?

Posted by Mike Kienenberger <mk...@alaska.net>.
SainTiss <sa...@gmx.net> wrote:
> Ok, so the java tool does the recursion. Do you mean something like 
passing 
> all relevant velocity variables to some java method, which then performs 
> recursion and puts the output in a stringbuffer, which is then passed to 
> velocity again and outputted there?
> 
> I guess I'm still wrong here, because in that case too much of the "view" 
part 
> would also be in the java tool, right?

No, you understand perfectly.

However, without seeing exactly what you're trying to accomplish, it's hard 
to say if "too much" view logic is being put into a tool.

In any case, as long as the tool doesn't restrict your template designers 
(or if you are your own template designer), it's not a problem.

Since you have complete control over what's sent into your tool, you should 
be able to allow a template designer to customize any view-specific output 
that your tool creates.

Ie, if you have a tool that displays a list of elements, your tool can allow 
the designer to specify whether to use <OL> or <UL> for the list type.  
(Alternately, you could just design the tool to output <LI> elements and the 
designer is expected to provide the <OL> or <UL> framework.)

A tool is simply an easy way to do computational tasks in velocity.

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: does velocity support recursive macro's?

Posted by SainTiss <sa...@gmx.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 16 March 2004 01:25, Claude Brisson wrote:
> >> However I'm gonna add what I've also been told when I asked this same
> >> question at this same place (two years ago! wouahou!) and found to be
> >> true
> >>
> >> : it is often better design to write a little java tool so that your
> >>
> >> recursive algorithm becomes a simple loop (but recursion is fun coding,
> >> true, true...).
> >
> > Could you elaborate a bit on this please? I know that, in theory, it is
> > possible to rewrite every recursive structure into a loop and vice versa,
> > but I don't really see how a java tool could be of any help there?
>
> nah, no need to give up recursion : the java tool does the recursion so
> that the view layer is free from it it's just a question of separation of
> concerns between computation and view logic, and one of the main reasons
> #local is still in purgatory.



Ok, so the java tool does the recursion. Do you mean something like passing 
all relevant velocity variables to some java method, which then performs 
recursion and puts the output in a stringbuffer, which is then passed to 
velocity again and outputted there?

I guess I'm still wrong here, because in that case too much of the "view" part 
would also be in the java tool, right?

Thanks,

Hans



>
> ----- Original Message -----
> From: "SainTiss" <sa...@arklinux.org>
> To: "Velocity Users List" <ve...@jakarta.apache.org>
> Sent: Monday, March 15, 2004 11:55 PM
> Subject: Re: does velocity support recursive macro's?
>
>
> Hi,
>
> On Monday 15 March 2004 22:52, Claude Brisson wrote:
> > > Maybe using recursive #parse statements?
> > > (although I'm guessing that's just textual substitution too...)
> >
> > You're guessing right. The proper way is to use the #local directive that
> > you'll find in the contrib section. See the faq to know how to plug in a
> > custom directive.
>
> Thanks for that tip... I'm going to look into that!
>
> > However I'm gonna add what I've also been told when I asked this same
> > question at this same place (two years ago! wouahou!) and found to be
> > true
> >
> > : it is often better design to write a little java tool so that your
> >
> > recursive algorithm becomes a simple loop (but recursion is fun coding,
> > true, true...).
>
> Could you elaborate a bit on this please? I know that, in theory, it is
> possible to rewrite every recursive structure into a loop and vice versa,
> but I don't really see how a java tool could be of any help there?
>
> Thanks,
>
> Hans
>
> > CloD
> >
> > ----- Original Message -----
> > From: "SainTiss" <sa...@arklinux.org>
> > To: <ve...@jakarta.apache.org>
> > Sent: Monday, March 15, 2004 8:43 PM
> > Subject: does velocity support recursive macro's?
> >
> >
> > Hi,
> >
> > Does velocity support the use of recursive macro's?
> >
> > I tried a simple one, which seems to work, but nevertheless I get an
> > error message in the log:
> > VM #recursiveMacro: error : too few arguments to macro. Wanted 2 got 0
> >
> > This seems to be a known problem, but now I'm wondering if I can just
> > ignore this an carry on?
> >
> > Also, from what I can see in my simple example, if I #set variables in
> > such a macro, the value is overwritten in every recursive call, and not
> > restored when the call returns to the above call. I guess that's normal,
> > since macro's are just textual substitution, rather than the building of
> > stackframes and the like, right?
> >
> > But is there a way to get the behaviour of recursive functions (i.e. with
> > a new context for each call)? Maybe using recursive #parse statements?
> > (although I'm guessing that's just textual substitution too...)
> >
> > Thanks,
> >
> > Hans

- -- 
Ark Linux - Linux for the Masses (http://arklinux.org)

Capitalism: 
You don't have any cows. The bank will not lend you money to buy cows, 
because you don't have any cows to put up as collateral.

Representative Democracy:
You have two cows. Your neighbors pick someone to tell you who gets the milk. 

In a world without walls and fences, who needs windows and gates?

Hans Schippers
2LIC INF
UA 2003-2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAVr4HXlnUYIbmLOQRAiv5AKCK8JkM7BoW3/+czG0icp+h/XIuLQCeOvvn
mAiak2x6diBf8jSJ7ocjDDg=
=HQ7O
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: does velocity support recursive macro's?

Posted by Claude Brisson <cl...@renegat.net>.
>> However I'm gonna add what I've also been told when I asked this same
>> question at this same place (two years ago! wouahou!) and found to be true
>> : it is often better design to write a little java tool so that your
>> recursive algorithm becomes a simple loop (but recursion is fun coding,
>> true, true...).

> Could you elaborate a bit on this please? I know that, in theory, it is
> possible to rewrite every recursive structure into a loop and vice versa, but
> I don't really see how a java tool could be of any help there?

nah, no need to give up recursion : the java tool does the recursion so that the view layer is free from it
it's just a question of separation of concerns between computation and view logic, and one of the main reasons #local is still in
purgatory.

Oh, by the way :

> This seems to be a known problem, but now I'm wondering if I can just
> ignore this an carry on?

Yes, you can ignore it. Maybe one day someone will find the time to blast it :-)

CloD

----- Original Message ----- 
From: "SainTiss" <sa...@arklinux.org>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Monday, March 15, 2004 11:55 PM
Subject: Re: does velocity support recursive macro's?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

On Monday 15 March 2004 22:52, Claude Brisson wrote:
> > Maybe using recursive #parse statements?
> > (although I'm guessing that's just textual substitution too...)
>
> You're guessing right. The proper way is to use the #local directive that
> you'll find in the contrib section. See the faq to know how to plug in a
> custom directive.

Thanks for that tip... I'm going to look into that!

> However I'm gonna add what I've also been told when I asked this same
> question at this same place (two years ago! wouahou!) and found to be true
> : it is often better design to write a little java tool so that your
> recursive algorithm becomes a simple loop (but recursion is fun coding,
> true, true...).

Could you elaborate a bit on this please? I know that, in theory, it is
possible to rewrite every recursive structure into a loop and vice versa, but
I don't really see how a java tool could be of any help there?

Thanks,

Hans

>
> CloD
>
> ----- Original Message -----
> From: "SainTiss" <sa...@arklinux.org>
> To: <ve...@jakarta.apache.org>
> Sent: Monday, March 15, 2004 8:43 PM
> Subject: does velocity support recursive macro's?
>
>
> Hi,
>
> Does velocity support the use of recursive macro's?
>
> I tried a simple one, which seems to work, but nevertheless I get an error
> message in the log:
> VM #recursiveMacro: error : too few arguments to macro. Wanted 2 got 0
>
> This seems to be a known problem, but now I'm wondering if I can just
> ignore this an carry on?
>
> Also, from what I can see in my simple example, if I #set variables in such
> a macro, the value is overwritten in every recursive call, and not restored
> when the call returns to the above call. I guess that's normal, since
> macro's are just textual substitution, rather than the building of
> stackframes and the like, right?
>
> But is there a way to get the behaviour of recursive functions (i.e. with a
> new context for each call)? Maybe using recursive #parse statements?
> (although I'm guessing that's just textual substitution too...)
>
> Thanks,
>
> Hans

- -- 
Ark Linux - Linux for the Masses (http://arklinux.org)

Capitalism:
You don't have any cows. The bank will not lend you money to buy cows,
because you don't have any cows to put up as collateral.

Representative Democracy:
You have two cows. Your neighbors pick someone to tell you who gets the milk.

In a world without walls and fences, who needs windows and gates?

Hans Schippers
2LIC INF
UA 2003-2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAVjRVXlnUYIbmLOQRAhTsAJwPE+eyRoWIMfUoah8m9/73WMhAPACeITGg
XR0hxoCKOwtlrbTxITp5MEI=
=66oN
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: does velocity support recursive macro's?

Posted by SainTiss <sa...@arklinux.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

On Monday 15 March 2004 22:52, Claude Brisson wrote:
> > Maybe using recursive #parse statements?
> > (although I'm guessing that's just textual substitution too...)
>
> You're guessing right. The proper way is to use the #local directive that
> you'll find in the contrib section. See the faq to know how to plug in a
> custom directive.

Thanks for that tip... I'm going to look into that!

> However I'm gonna add what I've also been told when I asked this same
> question at this same place (two years ago! wouahou!) and found to be true
> : it is often better design to write a little java tool so that your
> recursive algorithm becomes a simple loop (but recursion is fun coding,
> true, true...).

Could you elaborate a bit on this please? I know that, in theory, it is 
possible to rewrite every recursive structure into a loop and vice versa, but 
I don't really see how a java tool could be of any help there?

Thanks,

Hans

>
> CloD
>
> ----- Original Message -----
> From: "SainTiss" <sa...@arklinux.org>
> To: <ve...@jakarta.apache.org>
> Sent: Monday, March 15, 2004 8:43 PM
> Subject: does velocity support recursive macro's?
>
>
> Hi,
>
> Does velocity support the use of recursive macro's?
>
> I tried a simple one, which seems to work, but nevertheless I get an error
> message in the log:
> VM #recursiveMacro: error : too few arguments to macro. Wanted 2 got 0
>
> This seems to be a known problem, but now I'm wondering if I can just
> ignore this an carry on?
>
> Also, from what I can see in my simple example, if I #set variables in such
> a macro, the value is overwritten in every recursive call, and not restored
> when the call returns to the above call. I guess that's normal, since
> macro's are just textual substitution, rather than the building of
> stackframes and the like, right?
>
> But is there a way to get the behaviour of recursive functions (i.e. with a
> new context for each call)? Maybe using recursive #parse statements?
> (although I'm guessing that's just textual substitution too...)
>
> Thanks,
>
> Hans

- -- 
Ark Linux - Linux for the Masses (http://arklinux.org)

Capitalism: 
You don't have any cows. The bank will not lend you money to buy cows, 
because you don't have any cows to put up as collateral.

Representative Democracy:
You have two cows. Your neighbors pick someone to tell you who gets the milk. 

In a world without walls and fences, who needs windows and gates?

Hans Schippers
2LIC INF
UA 2003-2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAVjRVXlnUYIbmLOQRAhTsAJwPE+eyRoWIMfUoah8m9/73WMhAPACeITGg
XR0hxoCKOwtlrbTxITp5MEI=
=66oN
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: does velocity support recursive macro's?

Posted by Claude Brisson <cl...@renegat.net>.
> Maybe using recursive #parse statements?
> (although I'm guessing that's just textual substitution too...)

You're guessing right. The proper way is to use the #local directive that you'll find in the contrib section.
See the faq to know how to plug in a custom directive.
The one and only purpose of this directive is to create a local scope for the variable(s) you pass it.

For instance :

#local($foo $bar)
   ...block that uses $bar and $foo locally...
#end

However I'm gonna add what I've also been told when I asked this same question at this same place (two years ago! wouahou!) and
found to be true : it is often better design to write a little java tool so that your recursive algorithm becomes a simple loop (but
recursion is fun coding, true, true...).

CloD

----- Original Message ----- 
From: "SainTiss" <sa...@arklinux.org>
To: <ve...@jakarta.apache.org>
Sent: Monday, March 15, 2004 8:43 PM
Subject: does velocity support recursive macro's?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Does velocity support the use of recursive macro's?

I tried a simple one, which seems to work, but nevertheless I get an error
message in the log:
VM #recursiveMacro: error : too few arguments to macro. Wanted 2 got 0

This seems to be a known problem, but now I'm wondering if I can just ignore
this an carry on?

Also, from what I can see in my simple example, if I #set variables in such a
macro, the value is overwritten in every recursive call, and not restored
when the call returns to the above call. I guess that's normal, since macro's
are just textual substitution, rather than the building of stackframes and
the like, right?

But is there a way to get the behaviour of recursive functions (i.e. with a
new context for each call)? Maybe using recursive #parse statements?
(although I'm guessing that's just textual substitution too...)

Thanks,

Hans

- -- 
Ark Linux - Linux for the Masses (http://arklinux.org)

Capitalism:
You don't have any cows. The bank will not lend you money to buy cows,
because you don't have any cows to put up as collateral.

Representative Democracy:
You have two cows. Your neighbors pick someone to tell you who gets the milk.

In a world without walls and fences, who needs windows and gates?

Hans Schippers
2LIC INF
UA 2003-2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAVgdgXlnUYIbmLOQRAnmdAJ93S+RdwZiyaaD6/K+9z2kvXjEsWQCgi0DM
eVs0S86osyh08fPcIikOwk4=
=l8JA
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org