I am less confused than I was.
If "method" is still an open question, I will admit to a fondness for a pattern where there is a map of functions and a data map (possibly at least one data map) and the method arises by relating the function map to the data map.
Hi Graydon,
A method could be described as a function item in a map with at least one parameter, which is “supposed to” reference the containing map. In this context, it does not matter if the function item is an anonymous function, a partially applied function, named function references or any other reference. For example, the following three functions could be called methods:
let $get := map:get(?, 'data')
let $map := {
'data': 12,
'get-data1': fn($map) { map:get($map, 'data') },
'get-data2': map:get(?, 'data'),
'get-data3': $get
}
return (
$map =?> get-data1(),
$map =?> get-data2(),
$map =?> get-data3()
)
The current language design is lax enough that a processor has no way of determining whether a function is really a “method”. The following code succeeds, even though it makes no sense:
{ 'first': head#1 } =?> first()
Having said this, your question made me realize that the current version of the W3C draft doesn’t actually provide a proper definition of what is meant by “methods” in XQuery. This will probably need to be fixed.
Best,
Christian
________________________________________
Gesendet: Donnerstag, 26. März 2026 13:46
An: Christian Grün; BaseX; Eliúd Santiago Meza y Rivera
Betreff: Re: [basex-talk] Re: Fwd: Re: [XQST0045] Annotation %method is in reserved namespace.
Hi Christian,
The version 13 docs have "In XQuery, functions are called methods if they are embedded in maps."
I think something like
declare variable $icc:componentMap as map(*) := map {
'QR-code': icc:isQRcode#1,
'appendix': icc:isAppendix#1,
'backmatter': icc:isBackmatter#1,
....
wouldn't count because it's references, rather than embedded. (I think embedded = anonymous function definition in the map)
Right now that map gets used as
$icc:componentMap($elementName)($element)
to call a function based on which element it is to do something per-element-name to generate an ID component. (Sections have "Sec" prefixes, parts have "Part" prefixes, etc.)
I think the =?> operator doesn't provide a way to do this. The method arrow expects the data is ALSO in the map.
Am I wrong about that?
Thanks!
Graydon
On Thu, Mar 26, 2026, at 04:25, Christian Grün via BaseX-Talk wrote:
Dear Eliúd,
The syntax of method calls was changed in the 4.0 draft of the specification. The %method annotation was replaced by a "=?>" operator:
let $number := {
'value': 1,
'inc': fn { map:put(., 'value', ?value + 1) }
}
return $number =?> inc()
This is mostly syntactic sugar. In XQuery 3.1, the same code could have been written as:
let $number := map {
'value': 1,
'inc': function($map) { map:put($map, 'value', $map?value + 1) }
}
let $inc-function := $number?inc
return $inc-function($number)
The syntax of the newest version of BaseX is currently documented in the 13 branch of our Wiki [1,2]. Due to numerous changes in the spec, it is about time for a BaseX 13 release.
Hope this helps,
Christian
________________________________________
Gesendet: Donnerstag, 26. März 2026 03:06
An: BaseX
Betreff: [basex-talk] Fwd: Re: [XQST0045] Annotation %method is in reserved namespace.
I tested you suggestions and it's works, the last one with little variation:
let $number := {
'value': 1,
'inc': fn { map:put(., 'value', .?value + 1) }
}
return $number=?>inc()
I was testing 'cause I need to use values objects.
Thanks!!!!!
---------- Forwarded message ---------
Date: Wed, Mar 25, 2026 at 6:55 PM
Subject: [basex-talk] Re: [XQST0045] Annotation %method is in reserved namespace.
On 26/03/2026 01:12, Eliúd Santiago Meza y Rivera via BaseX-Talk wrote:
Hello,
let $vector := {
'x': 5,
'y': 6,
'sum': %method fn() { ?x + ?y }
}
return $vector =?> sum()
In the fiddle the variation
let $vector := {
'x': 5,
'y': 6,
'sum': fn { ?x + ?y }
}
return $vector =?> sum()
works
let $number := {
'value': 1,
'inc': %method fn() { map:put(., 'value', ?value + 1) }
}
return $number?inc()
as does
let $number := {
'value': 1,
'inc': fn { map:put(., 'value', ?value + 1) }
}
return $number=?>inc()
Not sure about the state of the annotation %method
--
LSC Eliud Santiago Meza y Rivera