vnext: Idle musings about choose/when

Hello world,

How much of an inconvenience is the requirement that all branches of a
choose/when have the same signature?

Suppose we eliminated that rule.

<p:choose name="run-stuff">
  <p:when test="not($moon-is-full) or ($today != $tuesday)">
    <p:output port="result" primary="true"/>
    <p:output port="secondary" step="xslt"/>
    <p:xslt name="xslt">…</p:xslt>
  </p:when>
  <p:otherwise>
    <p:output port="result"/>
    <p:identity>
      <p:document href="not-today.xml"/>
    </p:identity>
  </p:otherwise>
</p:choose>

Three new rules:

1. An explicit binding to an output port on a p:choose is allowed as
long as at least one of its branches defines a port with that name.
That means <p:input step="run-stuff" port="secondary"/> is ok,
but <p:input step="run-stuff" port="fribble"/> is a static error.

2. A p:choose has a primary output port if-and-only-if all of the
branches have a primary output port with the same name. So this choose
does have a primary output port: "result".

3. Any choose output that is not provided by the branch actually
evaluated at runtime gets an empty sequence. That means that
when the moon is full on Tuesdays,
<p:input step="run-stuff" port="secondary"/> gets an empty sequence.

We could relax rule 1 further and say any binding is allowed, but
that doesn’t seem like it would be helpful to the author.

We could relax rule 2 further and say that it has a primary output
port if any of its branches do. But that would have consequences that
seem extra weird to me. The primary output port is a convenience, it
can always be replaced by an explicit binding. But if we relaxed rule
2 so that any output that was primary in the selected branch was
bound, then that would no longer be true as the primary outputs might
have different port names in the different branches.

                                        Be seeing you,
                                          norm

-- 
Norman Walsh
Lead Engineer
MarkLogic Corporation
Phone: +1 512 761 6676
www.marklogic.com

Received on Tuesday, 18 October 2016 13:13:09 UTC