[stringtemplate-interest] Maps with object keys

Caleb Lyness caleb.lyness at ezswitch.net
Thu Nov 29 01:47:01 PST 2007


Hi Terence :-)

Terence Parr wrote:
>>> Hi Caleb! :) Heh, yeah, you're right...this is weird, though  
>>> consistent with what (x) means..(x) means "take the value of" or  
>>> "immediately eval" rather than lazy eval. Sometimes you need to  
>>> render an expression such as for keys with maps. It's an  
>>> indirection and immediate eval. m.x gives m.get("x") m.(x) gives  
>>> m.get(x.toString()) m.(x+"foo") gives m.get(x + "foo") hmm...we do  
>>> need a map look up with an object...i wonder what to do...
>>>       
>> Well as a step toward resolving the problem have a look at the  
>> attached test case.
>> Perhaps you would like to add it to TestStringTemplate and create  
>> an issue report
>> for the problem?
>>     
>
> Well, i should probably figure out what the "right" answer is before  
> adding an issue report...hmm...i don't see how to maintain (...)  
> functionality and backward compat and add obj-based key lookup.
Hmmm, right you are. So I guess a lazy evaluation would break the 
backward compatibility?
But how lazzy are we being...? I was thinking of something like:

> m.x gives m.get("x")
> m.(x) gives m.get(x.toString())
m.(x) gives

value = m.get(x)
if (value == null) value = m.get(x.toString())

or does this not make sense? It could also be done the other way round and look
for a string before the actual object. How far would this break backward 
compatibility? I don't have a full view of the bigger picture, so I will leave
that thought up to you.
> m.(x+"foo") gives m.get(x + "foo")

Alternatively how about a unary object reference operator... eg.
m.(&x) gives m.get(x)

Cheers
    Caleb.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071129/dd628bd2/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3269 bytes
Desc: S/MIME Cryptographic Signature
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071129/dd628bd2/attachment.bin 


More information about the stringtemplate-interest mailing list