I think that Dirk has summarized pretty well why the arity is required.
XQuery is both a strongly and weakly typed language: If the return type is known at compile time, the query optimizer can benefit a lot from type information. If XML data without schema information is processed, however, all nodes will be of type xs:untypedAtomic, and it will only be clear at runtime if the data will be processed as e.g. string or number. Beside that, the language does not require users to specify a type to variables and functions.
To still give the compiler a chance to assign function calls at compile time, it was decided to on the one hand disallow functions with the same number of arguments and of different type, but one the other hand make the specification of the arity obligatory.
If functions calls can be assigned at compile time, it is much easier to optimize the code. Otherwise, features like function inlining would all need to be performed at runtime. HotSpot or V8 are examples that this can work out pretty well, but if JavaScript had been a more strictly typed language, we would still have much faster web applications today.
On Fri, Nov 21, 2014 at 10:02 AM, Dirk Kirsten dk@basex.org wrote:
Hi Rob,
to be honest; I don't know. It is part of the XQuery 3.0 spec and I am sure the wise people who have written this spec have a reason to do so. I can think of a number of reasons to always include it:
- obviously, you will need it for some functions to identify them , because you could e.g. have two functions with the same name, but different arity. So if you need it for some, it could make sense to make it a requirement for all for consistency
- it could be for avoiding errors in the code. Suppose, in your function changes in a nwe version and now needs just one instead of two arguments. With the arity given in a function item, you can detect this at compile time. Without it, it is a runtime issue and potentially much more dangerous.
- I guess it is also slightly easier for an implementation to look up the function if the arity is given as well, as it can be a simple hash lookup. Without it, you might need to scan and find the right function. Although, to be honest, I think the overhead is negligible.
But if you really want to know the reasons and not just me thoughts, it might be better to ask on xquery-talk.
Cheers, Dirk
On 11/21/2014 09:08 AM, Rob Stapper wrote:
Hi Dirk,
I have to ask this: What is the "fun" of the function-arity to be a part of its identification. Which means that a property is part of an identification.
- Rob
-----Oorspronkelijk bericht----- Van: Dirk Kirsten [mailto:dk@basex.org] Verzonden: donderdag 20 november 2014 11:14 Aan: Rob Stapper CC: BaseX Onderwerp: Re: [basex-talk] small issue with map:put()
Hello Rob,
I have to admit this error message is not really helpful at all, but you are missing the arity. It should be
let $d := $c( $b, map:put#3)
i.e. you always have to give the artiy of the function if you want to get the function item.
Cheers, Dirk
On 11/20/2014 11:00 AM, Rob Stapper wrote:
Hi,
See attached snippet.
I get the error-message: no context value bound, on this one.
What's going wrong here?
Rob
Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus-bescherming actief is. http://www.avast.com
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22