You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Carsten Heyl <ca...@pixelboxx.de> on 2004/04/22 09:35:54 UTC

Velocitymacros broken?

Hi!

Recently I stumbled across the following oddity which is wrong behavior 
IMHO.

The User guide clearly states:

"When passing references as arguments to Velocimacros, please note that 
references are passed 'by name'. This means that their value is 
'generated' at each use inside the Velocimacro."

So when accessing a macro parameter i'm using the $param-Syntax.
So it's not a frefernce in this case, but a NAME(!)-parameter.

So why does the following happen:


#macro( metatextareamultifilled $value  $valueen)
:$!value:$value:$valueen:$!bean1.name:
#end

called with $bean1.name == null:

#metatextareamultifilled ($!bean1.name "$!bean1.name")

gives:

::$!bean1.name:::

I would expect
:::::

So in IMHO this is a clear break of call by name.

Comments?

Ciao,
	Carsten Heyl

-- 
   Carsten Heyl				cal@pixelboxx.de
   Pixelboxx GmbH			http://www.pixelboxx.de/
   Ostenhellweg 56-58			Tel.:   +49 231 53 46 30
D-44135 Dortmund


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


Re: Velocitymacros broken?

Posted by Terry Steichen <te...@net-frame.com>.
I believe you need to put curly brackets around  $bean inside the macro
(because Velocity gets mixed up
when you add a suffix such as '.name' to a varb).

I can't remember the exact syntax, but I think your expression should read
something like this:
    :$!value:$value:$valueen:$!{bean1.name}:

HTH,

Terry

----- Original Message ----- 
From: "Carsten Heyl" <ca...@pixelboxx.de>
To: <ve...@jakarta.apache.org>
Sent: Thursday, April 22, 2004 3:35 AM
Subject: Velocitymacros broken?


> Hi!
>
> Recently I stumbled across the following oddity which is wrong behavior
> IMHO.
>
> The User guide clearly states:
>
> "When passing references as arguments to Velocimacros, please note that
> references are passed 'by name'. This means that their value is
> 'generated' at each use inside the Velocimacro."
>
> So when accessing a macro parameter i'm using the $param-Syntax.
> So it's not a frefernce in this case, but a NAME(!)-parameter.
>
> So why does the following happen:
>
>
> #macro( metatextareamultifilled $value  $valueen)
> :$!value:$value:$valueen:$!bean1.name:
> #end
>
> called with $bean1.name == null:
>
> #metatextareamultifilled ($!bean1.name "$!bean1.name")
>
> gives:
>
> ::$!bean1.name:::
>
> I would expect
> :::::
>
> So in IMHO this is a clear break of call by name.
>
> Comments?
>
> Ciao,
> Carsten Heyl
>
> -- 
>    Carsten Heyl cal@pixelboxx.de
>    Pixelboxx GmbH http://www.pixelboxx.de/
>    Ostenhellweg 56-58 Tel.:   +49 231 53 46 30
> D-44135 Dortmund
>
>
> ---------------------------------------------------------------------
> 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: Velocitymacros broken?

Posted by Carsten Heyl <ca...@pixelboxx.de>.
Geir Magnusson Jr wrote:

>
> On Apr 22, 2004, at 3:35 AM, Carsten Heyl wrote:
>
>> Hi!
>>
>> Recently I stumbled across the following oddity which is wrong 
>> behavior IMHO.
>>
>> The User guide clearly states:
>>
>> "When passing references as arguments to Velocimacros, please note 
>> that references are passed 'by name'. This means that their value is 
>> 'generated' at each use inside the Velocimacro."
>>
>> So when accessing a macro parameter i'm using the $param-Syntax.
>> So it's not a frefernce in this case, but a NAME(!)-parameter.
>>
>> So why does the following happen:
>>
>>
>> #macro( metatextareamultifilled $value  $valueen)
>> :$!value:$value:$valueen:$!bean1.name:
>> #end
>>
>> called with $bean1.name == null:
>>
>> #metatextareamultifilled ($!bean1.name "$!bean1.name")
>>
>> gives:
>>
>> ::$!bean1.name:::
>>
>> I would expect
>> :::::
>>
>> So in IMHO this is a clear break of call by name.
>>
>> Comments?
>
>
> I started answering this arguing that your usage was non-sensical, but 
> then after thinking about it another 5 seconds, I think you are 
> right.  This is a bug.
>
> geir 

:-)

Maybe the use of "$!value" when referencing a formal parameter should be 
checked as an error (or a warning because currently it's the only way to
handle null values.

Ciao,
    Carsten

-- 
  Carsten Heyl				cal-velocity@pixelboxx.de
  Pixelboxx GmbH			http://www.pixelboxx.de/
  Ostenhellweg 56-58			Tel.:   +49 231 53 46 30
D-44135 Dortmund



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


Re: Velocitymacros broken?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Apr 22, 2004, at 3:35 AM, Carsten Heyl wrote:

> Hi!
>
> Recently I stumbled across the following oddity which is wrong 
> behavior IMHO.
>
> The User guide clearly states:
>
> "When passing references as arguments to Velocimacros, please note 
> that references are passed 'by name'. This means that their value is 
> 'generated' at each use inside the Velocimacro."
>
> So when accessing a macro parameter i'm using the $param-Syntax.
> So it's not a frefernce in this case, but a NAME(!)-parameter.
>
> So why does the following happen:
>
>
> #macro( metatextareamultifilled $value  $valueen)
> :$!value:$value:$valueen:$!bean1.name:
> #end
>
> called with $bean1.name == null:
>
> #metatextareamultifilled ($!bean1.name "$!bean1.name")
>
> gives:
>
> ::$!bean1.name:::
>
> I would expect
> :::::
>
> So in IMHO this is a clear break of call by name.
>
> Comments?

I started answering this arguing that your usage was non-sensical, but 
then after thinking about it another 5 seconds, I think you are right.  
This is a bug.

geir

>
> Ciao,
> 	Carsten Heyl
>
> -- 
>   Carsten Heyl				cal@pixelboxx.de
>   Pixelboxx GmbH			http://www.pixelboxx.de/
>   Ostenhellweg 56-58			Tel.:   +49 231 53 46 30
> D-44135 Dortmund
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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


Re: Velocitymacros broken?

Posted by Christoph Reck <ap...@recks.org>.
Parameters in velocimacros are to be used exaclty in the way they
were declared in the macro definition. So in your example, only
the two middle usages $value:$valueen are correct. The last one
also, since it is accessing the global variable.

The first one: $!value will not work - at least it was so up to
Velocity 1.2, I don't know if this was fixed the current version.
The bang "!" character makes the invocation different from the
declaration, and thus it is not defined. IMHO this is a bug.

But also having $!bean1.name passed into $value resulting in the
literal string seems to be another bug. Please file it into
Bugzilla.

Please try the invocation with no-null values first and ensure
it acts as expected (specially the $!value usage).

Cheers,
Christoph

Carsten Heyl wrote:
> Hi!
> 
> Recently I stumbled across the following oddity which is wrong behavior 
> IMHO.
> 
> The User guide clearly states:
> 
> "When passing references as arguments to Velocimacros, please note that 
> references are passed 'by name'. This means that their value is 
> 'generated' at each use inside the Velocimacro."
> 
> So when accessing a macro parameter i'm using the $param-Syntax.
> So it's not a frefernce in this case, but a NAME(!)-parameter.
> 
> So why does the following happen:
> 
> 
> #macro( metatextareamultifilled $value  $valueen)
> :$!value:$value:$valueen:$!bean1.name:
> #end
> 
> called with $bean1.name == null:
> 
> #metatextareamultifilled ($!bean1.name "$!bean1.name")
> 
> gives:
> 
> ::$!bean1.name:::
> 
> I would expect
> :::::
> 
> So in IMHO this is a clear break of call by name.
> 
> Comments?
> 
> Ciao,
>     Carsten Heyl
> 

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