Hi Christian,
For my recursive sequencer ( as I call it) I would like to have something like a 'hof:self()'-function.
This "hof:self()"-function would return the (declared) function where it is used in.
I have several functions that call another function with itself as one of the parameters:
For instance:
Declare function A( $p1) { X( $p1, ., A#1) } ;
Declare function B( $p1, $p2) { X( $p1, ., B#2) } ;
It would be nice if there was something like a "hof:self()"-function so that I could make these functions more generic.
For instance:
Declare function A( $p1) { X( $p1, ., hof:self()) } ;
Declare function B( $p1) { X( $p1, ., hof:self()) } ;
Is it something that would enrich the hof-module ?
Like to hear from you.
Rob Stapper
Hi Rob,
I must admit I didn’t fully understand your first example:
Declare function A( $p1) { X( $p1, …, A#1) } ;
What is X ? Do you have a (minimized) query available that runs out of the box, and show us the requested rewriting?
Christian
On Wed, Feb 1, 2017 at 1:21 PM, Rob Stapper r.stapper@lijbrandt.nl wrote:
Hi Christian,
For my recursive sequencer ( as I call it) I would like to have something like a ‘hof:self()’-function.
This “hof:self()”-function would return the (declared) function where it is used in.
I have several functions that call another function with itself as one of the parameters:
For instance:
Declare function A( $p1) { X( $p1, …, A#1) } ;
Declare function B( $p1, $p2) { X( $p1, …, B#2) } ;
It would be nice if there was something like a “hof:self()”-function so that I could make these functions more generic.
For instance:
Declare function A( $p1) { X( $p1, …, hof:self()) } ;
Declare function B( $p1) { X( $p1, …, hof:self()) } ;
Is it something that would enrich the hof-module ?
Like to hear from you.
Rob Stapper
Christian,
If I add:
Declare function X( $p1, ...., $f) { let $var := ........ return $f( $var)} ;
Does that clear things up? I will try to make some example in the weekend.
Rob
-----Oorspronkelijk bericht----- Van: Christian Grün [mailto:christian.gruen@gmail.com] Verzonden: woensdag 1 februari 2017 20:02 Aan: Rob Stapper CC: BaseX Onderwerp: Re: [basex-talk] request/suggestion
Hi Rob,
I must admit I didn’t fully understand your first example:
Declare function A( $p1) { X( $p1, …, A#1) } ;
What is X ? Do you have a (minimized) query available that runs out of the box, and show us the requested rewriting?
Christian
On Wed, Feb 1, 2017 at 1:21 PM, Rob Stapper r.stapper@lijbrandt.nl wrote:
Hi Christian,
For my recursive sequencer ( as I call it) I would like to have something like a ‘hof:self()’-function.
This “hof:self()”-function would return the (declared) function where it is used in.
I have several functions that call another function with itself as one of the parameters:
For instance:
Declare function A( $p1) { X( $p1, …, A#1) } ;
Declare function B( $p1, $p2) { X( $p1, …, B#2) } ;
It would be nice if there was something like a “hof:self()”-function so that I could make these functions more generic.
For instance:
Declare function A( $p1) { X( $p1, …, hof:self()) } ;
Declare function B( $p1) { X( $p1, …, hof:self()) } ;
Is it something that would enrich the hof-module ?
Like to hear from you.
Rob Stapper
Hi Christian,
Hereby a short out of the box example. Actually it is about the commented example which shows how this hof:self() function could be used but that does not run off course.
Rob
-----Oorspronkelijk bericht----- Van: Christian Grün [mailto:christian.gruen@gmail.com] Verzonden: woensdag 1 februari 2017 20:02 Aan: Rob Stapper CC: BaseX Onderwerp: Re: [basex-talk] request/suggestion
Hi Rob,
I must admit I didn’t fully understand your first example:
Declare function A( $p1) { X( $p1, …, A#1) } ;
What is X ? Do you have a (minimized) query available that runs out of the box, and show us the requested rewriting?
Christian
On Wed, Feb 1, 2017 at 1:21 PM, Rob Stapper r.stapper@lijbrandt.nl wrote:
Hi Christian,
For my recursive sequencer ( as I call it) I would like to have something like a ‘hof:self()’-function.
This “hof:self()”-function would return the (declared) function where it is used in.
I have several functions that call another function with itself as one of the parameters:
For instance:
Declare function A( $p1) { X( $p1, …, A#1) } ;
Declare function B( $p1, $p2) { X( $p1, …, B#2) } ;
It would be nice if there was something like a “hof:self()”-function so that I could make these functions more generic.
For instance:
Declare function A( $p1) { X( $p1, …, hof:self()) } ;
Declare function B( $p1) { X( $p1, …, hof:self()) } ;
Is it something that would enrich the hof-module ?
Like to hear from you.
Rob Stapper
Hi Rob,
Thanks for the example. So you would like to have a function that returns a function item, which references the function in which it is currently evaluated?
* Original version:
declare function local:f($v) { if($v > 0) then local:f($v - 1) else "OK" }; local:f(3)
* Version with hof:self():
declare function local:f($v) { if($v > 0) then $v + hof:self($v - 1)($v) }; local:f(3)
I haven’t thought about all the implications yet, but I believe that the addition of such a function would restrict the way how we code can be optimized. Take this query for example:
declare function local:add($x, $y) { $x + $y }; local:add(1, 2)
The query optimizer will inline the called function and simplify the expression to
1 + 2
In the following query…
declare function local:add() { hof:self() }; local:add()
…we would need to suppress query inlining because it would otherwise yield different results.
Cheers, Christian
basex-talk@mailman.uni-konstanz.de