Re: The map-lookup-forgiveness problem

"?" is modelled on "/", and "/" requires the LHS to deliver nodes, so this would be an inconsistency.

The language is already very inconsistent about whether it's a good idea to widen the domain of a function or operator to embrace items that can only deliver a trivial result for the operation. For example we widen the domain of name() to allow text nodes, but not to allow strings. The reason we're inconsistent is that there are benefits in doing it, and there are also benefits (type checking) in not doing it. Personally I think that a void result, with no error, is one of the hardest things to debug, and as a general rule I think it's a good idea to make it a type error to apply any operation to inappropriate operands. But there will always be arguments both ways.

Michael Kay
Saxonica

> On 7 Feb 2023, at 17:06, Dimitre Novatchev <dnovatchev@gmail.com> wrote:
> 
> At today's meeting Michael Kay asked for a detailed use-case for map returning a map with no keys as a result of a failed lookup.
> 
> Here is this described in https://github.com/qt4cg/qtspecs/issues/105 <https://github.com/qt4cg/qtspecs/issues/105>  "
> [XPath] Proposal: Maps with Infinite Number of Keys: Total Maps and Decorated maps #105
> "
> 
> 
> Using this representation of the empty sequence, we can provide a solution for the "Forgiveness problem" <https://xmlcom.slack.com/archives/C011NLXE4DU/p1616167871037100> raised by Jarno Jelovirta in the XML.Com #general channel in March 2021:
> 
> This expression will raise an error:
> 
> [map {"k0": 1}, map{"k0": [1, 2, 3]}]?*?("k0")?*
> [XPTY0004] Input of lookup operator must be map or array: 1.
> 
> To prevent ("forgive", thus "Forgiveness Problem") the raising of such errors we could accept the rule that in XPath 4.0 any expression that evaluates to something different than a map or an array, could be coerced to the following map, which returns the empty sequence as the corresponding value for any key requested in a lookup:
> 
> map {
> '\' : ()
> }  (: produces the empty sequence  for any lookup:)
> 
> Thanks,
> Dimitre

Received on Tuesday, 7 February 2023 17:30:13 UTC