velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Lee <>
Subject discarding method return values
Date Mon, 04 Nov 2002 05:57:45 GMT
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 = [] )

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 )

(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...


$_myHashMap.put("bus", "truck")



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.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message