- From: Michael Kay <mike@saxonica.com>
- Date: Tue, 7 Feb 2023 21:36:14 +0000
- To: "Liam R. E. Quin" <liam@fromoldbooks.org>
- Cc: public-xslt-40@w3.org
The null-coalescing operators are subtly different. With the expression E?X we already allow E to be an empty sequence, so in that sense it is already null-coalescing.
The question we're addressing, if I understand it correctly, is what to do when E is a sequence, and when it contains some items for which e?X is defined (i.e. maps and arrays) and other items for which e?X is not defined and throws an error.
There's a proposal to define ?? as a (kind of) transitive closure of ? (?? is to ? as // is to /, roughly), and I would certainly expect that to only go down the routes that are applicable, ignoring items that are not. If it finds a leaf node containing a string or number, it won't try to apply "?" to it recursively (obviously).
What's the objection to writing `E[. instance of map(*)]?X ` - is it just that's it's wordy?
Michael Kay
Saxonica
> On 7 Feb 2023, at 21:15, Liam R. E. Quin <liam@fromoldbooks.org> wrote:
>
> On Tue, 2023-02-07 at 12:29 -0800, Dimitre Novatchev wrote:
>> Addressing the "difficulty to debug" issue, this reminds me of C#
>> where
>> there are both the "." (member access) and "?." (null-conditional)
>> operators.
>>
>> https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and
>> -
>>
>
> This has recently been added to JavaScript too as i understand it.
>
> There is also the null-condensing operator ?? in which a ?? b is like
> our (a, b)[1]. So i think we should avoid using ?? to mean something
> similar but subtly different; || is bad enough already :)
>
> JavaScript has ?. as null-safe property access, and this has widespread
> support. See
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#browser_compatibility
> function printCustomerCity(customer) {
> const customerCity = customer?.city ?? "Unknown city";
> console.log(customerCity);
> }
>
> which uses both of these operators.
>
> As a side-note, there are also nullish assignment operators, e.g.
> a ??= e;
> is like XPath's
> a := if (a) then a else e
> except we can't update variables of course, so this is pernicious
> shadowing...
>
> and ||= and &&=, neither of which we could use :)
>
> But i think we probably should avoid using ?? to mean the same as
> JavaScript and C# ".?" - this will especially confuse SaxonJS users :)
> and lead to bugs that are hard to find.
>
> I do however think a safe dereference operator is a good idea, and if
> it wasn't for JS using ?? in that way, i'd like ?? for it.
>
> Maybe we should use ‽ instead :) or allow [.]? to work that way, so
> e1[.]?e2
> returns () if e1 is empty, e1?e2 if e1 is a map, and an error
> otherwise.
>
> liam
>
> --
> Liam Quin, https://www.delightfulcomputing.com/
> Available for XML/Document/Information Architecture/XSLT/
> XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
> Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org
>
Received on Tuesday, 7 February 2023 21:36:28 UTC