Re: New Functions

Can we discuss these additions:

1.     I propose, to make good use of the new   tuple / record  type, and
make the fn:apply() function more precise by giving it a  record  as the
argument:

fn:apply($function as function(*), tuple as tuple(*)) as item()*



2.      We could enhance  fn:function-lookup( )  to lookup for a function
within a provided sequence of functions or functions that are values within
a map-hierarchy,
that don't have to be named functions, and that have a given signature
(record consisting of the arguments types and the result type).
The new function will generally return function(*)*,  that is, a possibly
empty sequence of functions:

fn:function-lookup($funcs as function(*)*,
                   $signature as tuple(*))
           as function(*)*





3. A new function  fn:function-type()   that given any function
returns a  tuple
 that is the *signature* of the given function. We define the *signature*
of a function as a tuple of the types of its arguments and (as a last tuple
item) the return type of that function:


fn:function-type($f as function(*)) as tuple(*)



Thanks,
Dimitre

On Fri, Nov 27, 2020 at 11:30 AM Michael Kay <mike@saxonica.com> wrote:

> Welcome!
>
> The current list of new and changed functions I've included in the F&O
> proposal is as follows:
>
>
> https://htmlpreview.github.io/?https://github.com/qt4cg/qtspecs/blob/master/specifications/xpath-functions-40/html/Overview-diff.html
>
> fn:stack-trace() - seems useful and general enough to put in the spec
> rather than making it an extension function
>
> fn:is-NaN() - a simple utiltiy function, included because the standard
> ways of doing this ($X ne $X) are so obscure
>
> fn:format-number() - allow the decimal format name to be supplied as an
> xs:QName rather than a string, to remove context dependency
>
> fn:characters() - split a string into characters; included because the
> workaround (string-to-codepoints() ! codepoints-to-string()) is bizarre
>
> fn:replace-with() - replace but supplying the replacement string as a
> function - included because when you've discovered this in Javascript, it
> starts to become indispensible (and because we ought to be making more use
> of higher-order functions now we have them)
>
> fn:in-scope-namespaces() - combines fn:in-scope-prefixes() and
> fn:namespace-uri-for-prefix() into a single function that returns a map;
> included because the current functions are a clumsy workaround and it can
> be done so much more elegantly with maps
>
> fn:identity() - because an identity function is useful with callbacks
>
> fn:replicate() - handy for string padding in particular
>
> fn:slice() - allows much more general selective extraction of items from a
> sequence. Broadly equivalent to $seq[position() = $integers] but doesn't
> suffer from the drawback that the integers are computed in a new context.
>
> fn:differences() - like deep-equal, but (a) provides options as to how the
> comparisons are performed, (b) drops the things deep-equal got wrong (like
> stripping comments without combining the resulting adjacent text nodes),
> and (c) tells you where the differences were found. Main use case is for
> testing (comparison of expected results).
>
> fn:uniform() - tests if all values in a sequence are the same. Main use
> case is for assertions in validation; provided because it's clumsy to write
> it by hand, and probably inefficient
>
> fn:unique() - tests if all values in a sequence are different. Ditto.
>
> fn:all() - functional equivalent of the "every" expression
>
> fn:some() - functional equivalent of the "some" expression
>
> fn:index-where() - like fn:index-of(), but using an arbitrary predicate
> rather than a simple equality test
>
> fn:items-before(), items-after(), items-until(), items-from() - enables
> selection of a subsequence before/after the first item matching a
> predicate. Provided because this is notoriously hard to to at the moment,
> and higher-order functions make it easy.
>
> fn:highest(), fn:lowest() - unlike min/max, these return the nodes
> (typically) that contain the min/max values rather than the min/max
> themselves. Much more efficient than first finding the max and then finding
> which element it came from.
>
> map:filter() - selects multiple entries from a map using a predicate.
>
> map:substitute() - effectively a map operation applied to a map: computes
> new values for all the entries by applying a function
>
> map:index() - constructs a map by indexing a sequence, using a supplied
> function to compute the key. (A much more flexible alternative to xsl:key)
>
> fn:json() - converts any XDM value to a JSON representation.
>
> I'm also proposing to change eq, distinct-values() etc to do numeric
> comparison using the same rules as op:same-key, which makes it transitive.
> The only change is when you compare a decimal and a double that are very
> close to each other; the double is now converted to a decimal, avoiding
> rounding errors, which was the source of the non-transitivity.
>
> If you have any comments, or suggestions for new functions, open an issue
> at https://github.com/qt4cg/qtspecs. I suggest using [FO40] at the start
> of the title.
>
> Michael Kay
> Saxonica
>
>
>
>

Received on Sunday, 29 November 2020 19:43:38 UTC