[stringtemplate-interest] The length of things

Tom Bentley tom at egressive.com
Sun May 15 17:53:57 PDT 2005


>>> The problem is that it's ambiguous.  it would also be yet another   
>>> place where a type would have to be assumed to resolve the   
>>> ambiguity.  But, I'm not ncessarily totally opposed.
>>>
>>
>> FWIW, I think getting the length of an array is a must.
> 
> 
> To be consistent, I'd have to do it for any iteratable thingie.

Well, only if StringTemplate is not making a conceptual distinction 
between the two.

It seems sensible for the looping constructs in StringTemplate to assume 
it's dealing with an iterable.

But is it necessary to lump arrays, collections and arbitrary iterables 
together when it come to other parts of ST, like testing for emptyness, 
or getting the length/size of a thing?

It feels like this is Sun's fault for having all these different 
length-like things (String.length(), Collection.size(), array.length): 
Python just treats them all as a unified concept.

If you're drawing the special-case-code line at Strings, arrays and 
Collections, you could invent something along the lines of pythons len() 
and hard-code its behaviour for these types.

It /is/ messy though.

>> Support for accessing length() and an isEmpty()-like predicate on  
>> String and size()/isEmpty() on java.util.Collection and  java.util.Map 
>> would also be useful.
> 
> 
> Well, you test foo.isEmpty by $if(foo)$; zero length things now test  as 
> not there (next release).

Ah ha, the next release: Any idea when that might happen?

Cheers,

Tom


More information about the stringtemplate-interest mailing list