[cduce-users] Transformation d'une liste

Alain.Frisch at ens.fr Alain.Frisch at ens.fr
Sat Jul 26 15:47:25 CEST 2003


On Sat, 26 Jul 2003, Giuseppe Castagna wrote:

> Personnally I not fully convinced that the advantages are worth the more
> complicated syntax. I would (and I did) defend, the elimination of
> transform and the use of the default branch for map, but I'd like to
> have some user feedback on the issue.

1. What default branch for map ?   _ -> []  or   x -> x  ?

2. In practice, transform seems more useful for XML processing. Why would
you want to eliminate it and force the programmer to use flatten
everywhere ?

3. As for the default branch for transform, I'm quite relectant to it: it
can easily hide errors from the programmer. It would'nt be such a burden
to add the "_ -> []" branch explicitly when needed.

There is also this discrepancy between transform and xtranform:
xtransform copies unmatched elements, and transform deletes them. This
should probably be fixed at some point.


4. Suggestion to get rid of square brackets (I guess this is what you
refer to with the "more complicated syntax") in branches of transform (and
xtransform) that returns a single element: it is possible to generalize
the flatten operator to automatically convert any value except pairs to
the singleton sequence.

So: flatten [ <a>[] <b>[] <c>[] [ <d>[] <e>[] ] <f>[] ] =>
    [ <a>[] <b>[] <c>[] <d>[] <e>[] <f>[] ]

This allow to write:

transform e with p1 -> e1 | p2 -> [ e2 e3 ]

instead of:

transform e with p1 -> [ e1 ] | p2 -> [ e2 e3 ]

Alternatively, it is possible to have transform replace the result
of a branch with a singleton sequence when the result is not a pair.
This would give a similar effect.

The map construction would then be useful only for explicitly
not flattening sequences.

5. A common construction is: transform e with x -> f x where f is
a function. Maybe we should propose a shorter construction for this, like
"transform e with fun f", or "f* e".

----

Comment ?


-- Alain




More information about the Cduce-users mailing list