[stringtemplate-interest] The length of things
Terence Parr
parrt at cs.usfca.edu
Tue May 24 16:32:42 PDT 2005
On May 15, 2005, at 5:53 PM, Tom Bentley wrote:
>>>> 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.
It usually does. It converts everything to Iterators I think.
> 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?
Hmm...I have single valued and multi-valued attribute concepts...I
think length makes sense for those as how many in the collection. As
for individual objects, how can we know whether you meant how many
strings and how long is this particular string? Hmm...good question.
> 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.
Yeah, let's blame them :)
> 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.
Yeah. :(
>>> 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?
When people pressure me to do so I guess ;)
Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
More information about the stringtemplate-interest
mailing list