Discussion:
[xquery-talk] xquery 3.1 wishlist
Christophe Geiser
2015-07-06 07:30:37 UTC
Permalink
Dear all,
Thanks Wouter for initiating this discussion.

I’d like to add another feature request to the current implementation of
the language : the ability to retrieve the current function being executed.
I could not find a work-around for implementing this, and - now with
functions being first-class citizens of the language - felt the need for
this capability in some edge cases.

Something like :


declare function local:test($arg) {
let $function := function-item() (: would return local:test#1 as
function item :)
return ()
};

Thanks and best regards,
Christophe Geiser


------------------------------

Hello,
I’ve been working with the recent xquery 3.1 implementation in the develop
branch eXist-db. I encountered some cases that were quite hard to work
around:

- the lack of array:index-of() - the lack of the iterator index in
arrayfor-each and related higher-order functions
Perhaps someone of the workgroup is available to discuss those
cases. Thanks,
Wouter

W.S. Hager Lagua Web Solutions http://lagua.nl
​
--
<https://www.e-smile.org>

<https://plus.google.com/+E-smileOrg> <https://twitter.com/esmileSolution>
<https://github.com/e-smile>


*Christophe Geiser*Founder of e-smile

e-smile.org

Never give up on a dream just because of the time it will take to
accomplish it. The time will pass anyway.
Michael Kay
2015-07-06 08:09:23 UTC
Permalink
Adding capability to XQuery 3.1 at this stage will require a more convincing justification than “I felt the need for this in some edge cases”.

Are there other functional languages that offer such a feature?

Michael Kay
Saxonica
Post by Christophe Geiser
Dear all,
Thanks Wouter for initiating this discussion.
I’d like to add another feature request to the current implementation of the language : the ability to retrieve the current function being executed. I could not find a work-around for implementing this, and - now with functions being first-class citizens of the language - felt the need for this capability in some edge cases.
declare function local:test($arg) {
let $function := function-item() (: would return local:test#1 as function item :)
return ()
};
Thanks and best regards,
Christophe Geiser
Hello,
the lack of array:index-of() - the lack of the iterator index in arrayfor-each and related higher-order functions
Perhaps someone of the workgroup is available to discuss those cases.
Thanks, Wouter
W.S. Hager Lagua Web Solutions http://lagua.nl <http://lagua.nl/>
--
<https://www.e-smile.org/>
<https://plus.google.com/+E-smileOrg> <https://twitter.com/esmileSolution> <https://github.com/e-smile>
Christophe Geiser
Founder of e-smile
e-smile.org <http://e-smile.org/>
Never give up on a dream just because of the time it will take to accomplish it. The time will pass anyway.
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Christophe Geiser
2015-07-06 10:15:06 UTC
Permalink
On Mon, Jul 6, 2015 at 10:09 AM, Michael Kay <***@saxonica.com> wrote:

Adding capability to XQuery 3.1 at this stage will require a more
Post by Michael Kay
convincing justification than “I felt the need for this in some edge cases”.
On Mon, Jul 6, 2015 at 10:40 AM, Christian GrÃŒn
[***@gmail.com](mailto:***@gmail.com)
<http://mailto:[***@gmail.com](mailto:***@gmail.com)>
wrote:

The function call might disappear in the evaluated code, and the
Post by Michael Kay
resulting expression "123 + 456" might include no reference to the
original function anymore.
Thanks Michael and Christian,

Understood and agreed. I was not aware that 3.1 was so close from final and
did not mean to be insistent. So far, I am not aware of other Functional
languages proposing this type of feature, so consider this request as
closed ; )

Best,
Christophe

P.S.
Just to elaborate on one example “edge case”, this the type of pattern I
use for some restxq resource functions (Adam’s Retter eXist
implementation). It has the advantages of attaching higher level success
and error messages as metaData to resource functions. Having a
function-item() function returning the current function being executed
would avoid re-typing the function item local:myResourceFunction#arity when
the signature of the function changes - not much more convincing as a
justification !

declare
%rest: ... restxq annotation for the function
%msg:success('successKey', 'successMessage'),
%msg:error('errorKey', 'errorMessage'),

function local:myResourceFunction($args) {
let $fn:= function() {
let $initialCheck := loginAttemptAndOtherChecks($args) (:
throw an exception if not succesfull:)
let $doTheWork:= local:doTheWork($args)
}
return local:processResoureFunction($fn, local:myResourceFunction#arity)
};

declare function local:processResourceFunction($fn, $callee ) {
try {
$fn(),
local:retrieveSuccessMessage($callee)

} catch * {
local:retrieveErrorMessage($callee, $err:code, $err:description,
$err:value)
}
};

declare function local:doTheWork() {
(: do the work here, throw exceptions on errors:)
};

​

Loading...