Re: function library summary and issues

On 2010-11-24, at 20:57, Andy Seaborne wrote:

>> Even some strongly typed languages have this sort of oddity, e.g. Java's StringBuffer.append() appears to take a bunch of types as an argument, but + only works on pairs of numeric types, or strings, as far as I can tell. Not being a java user, I don't know how this pans out in practice.
> 
> http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
> 
> + works on strings if the LHS is a string.
> It is exactly StringBuffer.append.
> Oddly, it makes that use of "+" non-commutative.

Ah, I see, so it's not true overloading, but more like type-sensitive syntactic sugar, as the type can (normally?) be determined at compile time.

> The RHS is converted to a string by (1) whatever the base type conversion is (int, long, etc) or (2) Object.toString().
> 
>        String x = ""+1+2 ;
> ==>
> 	the string "12"
> 
> That's not a good for SPARQL IMO, where just string+string -> string is convenient.

Presumably string/plain literal? Otherwise it will fail often.

It still strikes me as user-hostile to overload operators in a weakly typed language, the resulting type of ?x + ?y is completely unpredictable. People who intend it to be a numeric expression will have to cast, or add 0, or do some equivalent hack. c.f. Javascript. Or more likely, they won't do any of that, and will be surprised by the result.

?x * ?y -> numeric, or error
?x / ?y -> numeric, or error
?x - ?y -> numeric, or error
?x + ?y -> numeric, xsd:string, plain literal(?), or error

- Steve

-- 
Steve Harris, CTO, Garlik Limited
1-3 Halford Road, Richmond, TW10 6AW, UK
+44 20 8439 8203  http://www.garlik.com/
Registered in England and Wales 535 7233 VAT # 849 0517 11
Registered office: Thames House, Portsmouth Road, Esher, Surrey, KT10 9AD

Received on Thursday, 25 November 2010 09:16:17 UTC