Re: Unifying Iteration and Viewports

Alex Miłowski <alex@milowski.com> writes:
> In the proposal we had iteration using the "bang operator" (!).  For
> example, if we have a sequence of documents in $seq and want to apply
> a single "filter step":
>
>    $seq ! filter()
>
> which is nice because the left hand side is nominally always a
> sequence and the semantics are clear in that the step signature (or
> flow expression) must have a single input and single output.  As such,
> the result is a sequence of the same length.

Not necessarily. Suppose filter() produces two outputs for some
inputs?

> This is opposed to some syntax for a "for loop" where the inputs and
> outputs need to be declared
>
>   for $x in $seq output $y  $x → step() ≫ $y

How does this generalize to a loop that consumes one input but
produces two outputs?

> IMHO, we could do this well if select/projections were in the language
> as a native construct:
>
> Straw man syntax:
>
> (A) An iteration of the sections that produces a sequence:
>
>    $doc//section ! filter()
>
> (B) An iteration of the sections that produces an empty sequence:
>
>    $doc//section ! sink()
>
> (C) replacement of sections
>
>   $doc ~ //section ! filter() ~
>
>   The replacement always starts with something that generates a
> sequence but we use the tilde to indicate where the bookkeeping starts
> and ends.

Maybe. But it’s pretty subtle, syntactically. Can we explore some
wordier alternatives?

$doc -> replace "//section" with filter()

I’m not sure, grammatically, what follows “with”.

>   This would be identity (or an error):
>
>   $doc ~ //section ~

$doc -> replace "//section" with identity()

> (D) replacement with a step chain (a nice shorthand)
>
>   $doc ~ //section ! A() → B() → C() ~

It’s not immediately obvious to me if this works or not:

$doc -> replace "//section" with A()  → B() → C()

> (F) replacement that effectively deletes:
>
>   $doc ~ //section ! [$in,$out] { $in → A() → B() → C()  } ~
>
>    We could allow this or make it an error as we do in XProc 1.0

I’m not sure that’s an error in XProc 1.0. It’s ok if the viewport
transformation produces nothing. It just can’t be an unbound output
port. Not sure how that applies here.

> Comments:
>
> 1. The projections in (A) and (B) can be done with a step:
>
>    $doc → select("//section") ! filter()
>
> 2. Using a step for projections allows the expression to be computed:
>
>    $params → select("/option[@name='target']/@expr") ≫ $expr
>    $doc → select($expr) ! filter()

Right. And allows for different projection steps for different media
types.

I wonder if this would be a reasonable alternative to “!” which also
doesn’t really make me happy.

$doc -> foreach "//section" do filter()

                                        Be seeing you,
                                          norm

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

Received on Wednesday, 16 March 2016 21:19:10 UTC