Re: What is a pragma?

Norm Tovey-Walsh writes:

>>> We take the position that conformant interpretation of pragmas should
>>> not alter the semantics of an ixml grammar.
>>
>> What does "the semantics of an ixml grammar" mean?
>>
>> What does it mean to alter the semantics?
>
> I thnk what I had in mind was something like the following: if a grammar
> without pragmas recognizes a certain set of sentences, adding pragmas to
> the grammar shouldn’t change the set of sentences it recognizes.

That's an interesting place to draw the line; I'm glad I asked, since I
would have guessed something else.

That might work, assuming a certain amount of wiggle room in that
"should".


>>> (You can’t have a conformant pragma that changes the rules!)
>>
>> How would that be enforced?
>>
>> Is the enforcement mechanism that if someone defines a pragma that
>> changes the rules (whatever that might be taken to mean), other people
>> have the right to point at that pragma and say "that one is a
>> non-conforming pragma"?
>
> Yes. Except that I’d probably phrase that as “use of this pragma makes
> the processor behave in a non-conformant way on this grammar.”

Good point.  We currently define conformance for grammars and
processors; we probably don't want to add pragmas as a conformance
class.  I think it might be nice to have a concise term for pragmas of
this class.

I suppose one question that arises is whether including such a pragma
makes a grammar non-conforming.

>>> We think Tom and Michael
>>> might disagree and look forward to their spirited input :-)

>> Do pragmas in XQuery change the semantics of the query in which they are
>> embedded?  Or do they leave the semantics of the query as they are
>> defined by the XQuery spec alone, even when they request that processors
>> capable of evaluating the alternate expression inside the pragma
>> evaluate that expression in place of the 'fallback expression'?

> That’s an interesting question. If I write an XQuery pragma that returns
> “3” for a fallback expression of “1 + 1”, is that a different semantic,
> or just a weird query?

I suspect the verdict of those in the XQuery WG with a taste for this
kind of question would be that the standard semantics of the XQuery are
unaffected, and the semantics of the pragma clearly differ but do not
render the query as a whole non-conformant or suspect in any
conformance-related way.  (In practice, yes, suspect.  But you know --
your gun, your bullet, your foot.)  That, at least, is how I read the
discussion of pragmas in the spec.

> If I write an XQuery pragma that takes an XPath expression as an
> argument and evaluates it in an environment where “+” is interpreted to
> mean subtraction and “-” is interpreted to mean addition, but I write a
> pragma that evaluates “3-3” for a fallback expression of “3+3”, is that
> a different semantic, or just a weird query?

My, what a dirty mind you have!  But you know -- what you get up to in
the privacy of your own CPUs ...

More seriously, I think the XQuery spec avoids having to answer that
question by saying explicitly that the semantics of extension
expressions are implementation-defined and NOT saying that they must not
alter the semantics of the query.

That reticence allows them to avoid all sort of theological tangles when
it comes to conformance judgements.  It also allows XQuery extension
expressions to be used in cases where the standard semantics can
approximate the desired answer but only an extension can produce it
exactly.  (Maybe the extension expression uses arbitrary-precision
arithmetic, or subtly different rounding rules.  Or maybe the extension
expression has side effects.)

One snag in the rule suggested: if a pragma should not change the set of
sentences recognized by a grammar, then doesn't a pragma meaning "reject
input of length greater than n characters" fall on the wrong side of the
line?  Unless the grammar would in any case reject all such sentences,
in which case why the pragma?

I think it might be cleaner and simpler to say that the standard
semantics of the grammar is as defined in the spec, that the semantics
of a pragma are implementation-defined, and that the presence or absence
of pragmas has, by definition, no effect on the standard semantics of
the grammar.

If people want to add that implementations SHOULD refrain from defining
pragmas which change the set of input sentences accepted by a grammar, I
think I would urge them to think again, but I don't currently think I
would lie down in the road over it.  A MUST would bother me more,
though, because it makes what looks like a potentially very tricky
question into a conformance criterion.

Thank you for the answer.

-- 
C. M. Sperberg-McQueen
Black Mesa Technologies LLC
http://blackmesatech.com

Received on Saturday, 29 January 2022 16:16:56 UTC