Returning functions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Returning functions

Norman Walsh
Hi,

Before I go digging, I thought I'd just start with a simple check to
see if what I want to do is possible...

Can I write an extension function (in Java, for example) that returns
a function reference?

  let $foo := my:function(1,2,3)
  let $bar := $foo("test")

Pointers to an example would be lovely but just a thumbs up/thumbs
down is enough for starters :-)

                                        Be seeing you,
                                          norm

--
Norman Walsh <[hidden email]> | In the life of saints, technically so
http://nwalsh.com/            | called, the spiritual facilities are
                              | strong, but what gives the impression
                              | of extravagance proves usually on
                              | examination to be a relative deficiency
                              | of intellect.--William James

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

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 

signature.asc (178 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Returning functions

Michael Kay
Norm,

The answer is almost certainly yes, but it might not be completely plain sailing…

And it could change significantly between 9.6 and 9.7, because we’ve done a lot of internal cleaning up in the way functions are represented.

In principle you can return any object that implements net.saxon.sf.om.FunctionItem.

Assuming you’re not constrained to HE, the easiest is probably to instantiate com.saxonica.hof.CallableFunctionItem, whose constructor takes some metadata about the function, plus a Callable object, which can be anything with a suitable call() method to invoke the function.

In fact, it’s probably not too difficult to implement FunctionItem directly.

It’s possible, however, that there are paths in Saxon that expect a FunctionItem to belong to a known implementation class.

Michael Kay
Saxonica

> On 29 Sep 2015, at 23:15, Norman Walsh <[hidden email]> wrote:
>
> Hi,
>
> Before I go digging, I thought I'd just start with a simple check to
> see if what I want to do is possible…
>
> Can I write an extension function (in Java, for example) that returns
> a function reference?
>
>  let $foo := my:function(1,2,3)
>  let $bar := $foo("test")
>
> Pointers to an example would be lovely but just a thumbs up/thumbs
> down is enough for starters :-)
>
>                                        Be seeing you,
>                                          norm
>
> --
> Norman Walsh <[hidden email]> | In the life of saints, technically so
> http://nwalsh.com/            | called, the spiritual facilities are
>                              | strong, but what gives the impression
>                              | of extravagance proves usually on
>                              | examination to be a relative deficiency
>                              | of intellect.--William James
> ------------------------------------------------------------------------------
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: Returning functions

Norman Walsh
Michael Kay <[hidden email]> writes:
> Assuming you’re not constrained to HE, the easiest is probably to

Uhm...how much harder is it likely to be if I want it to work in HE?

                                        Be seeing you,
                                          norm

--
Norman Walsh <[hidden email]> | Criminal: A person with predatory
http://nwalsh.com/            | instincts who has not sufficient
                              | capital to form a corporation.--Howard
                              | Scott

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

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 

signature.asc (178 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Returning functions

Michael Kay
HE doesn’t support higher order functions (they're an optional XPath 3.0 feature), so the parser won’t allow dynamic function calls, which means that even if you succeeded in passing a function item back from your Java code, there wouldn’t be very much you could do with it.

Michael Kay
Saxonica

> On 30 Sep 2015, at 13:49, Norman Walsh <[hidden email]> wrote:
>
> Michael Kay <[hidden email]> writes:
>> Assuming you’re not constrained to HE, the easiest is probably to
>
> Uhm...how much harder is it likely to be if I want it to work in HE?
>
>                                        Be seeing you,
>                                          norm
>
> --
> Norman Walsh <[hidden email]> | Criminal: A person with predatory
> http://nwalsh.com/            | instincts who has not sufficient
>                              | capital to form a corporation.--Howard
>                              | Scott
> ------------------------------------------------------------------------------
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help