velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph.R...@dlr.de
Subject Re: discarding method return values
Date Mon, 04 Nov 2002 09:31:59 GMT
I created a macro for this:

#macro( call $foo )#if( $foo )#**##end#end

since the #set(...) you used might cough and emit a log message when
the call returns null.

Since it is a major issue to keep velocity simple, we should not
add another criptic feature. When you want to explicitly do something
apart from normal, do it expicitly and with clear text.

Still I believe Velocity-land would profit from a base library of
extended directives and macros: $encode, #call, #local, etc.

Just my 2c...


Andy Lee wrote:
> I have a question related to the recent one about forcing all references 
> to be quiet.  I didn't see an answer in the docs, but feel free to tell 
> me "It's right there, you dope!"
> 
> I often want to discard the return values of methods.  For example, I 
> might have:
> 
> 
> #set( $myArray = [] )
> $myArray.add(1)
> $myArray.add(2)
> $myArray.add(3)
> 
> 
> Because add(Object) returns a boolean, this displays "true" three times, 
> which is not what I want.  My first workaround was this:
> 
> 
> #set( $ignore = $myArray.add(1) )
> #set( $ignore = $myArray.add(2) )
> #set( $ignore = $myArray.add(3) )
> 
> 
> This works, but seeing the word #set bugged me because I really don't 
> want to set anything.  My next workaround was to write a macro that 
> hides the #set:
> 
> 
> #macro( silently $foo )
> #set( $foo = $foo )
> #end
> 
> 
> (The reason for having the useless #set is that empty macros never seem 
> to get called.  I'm guessing they get optimized away.)
> 
> Now I can do:
> 
> 
> #silently( $myArray.add(1) )
> #silently( $myArray.add(2) )
> #silently( $myArray.add(3) )
> 
> 
> I'm comfortable with this in many cases, but I wonder if it would be 
> awkwardly verbose in others.
> 
> Would it be worth adding syntax that causes references *never* to print, 
> regardless of their value?  I.e., not only "quiet" but "mute"? Something 
> like...
> 
> 
> $_myArray.add(1)
> 
> $_myHashMap.put("bus", "truck")
> 
> $_myStringBuffer.append($lastName)
> 
> 
> ...?
> 
> Maybe the underscore character is a bad choice, because it could look 
> like part of the variable name, even though it can't be.  I kind of like 
> it because it connotes nothingness.  But whatever.
> 
> --Andy
> 
> -- 
> To unsubscribe, e-mail:   
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:velocity-user-help@jakarta.apache.org>
> 
> 

-- 
:) Christoph Reck


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


Mime
View raw message