Giuseppe.Castagna at ens.fr
Sun Jul 27 13:51:25 CEST 2003
Alain.Frisch at ens.fr wrote:
> 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.
First, I do not want to reopen the disccussion about map and transform but just give
an idea to users at cduce about why we ended
up with two similar constructions. I still think that what we actually have is
the best possible trade off, but again I'm open to suggestions.
> 1. What default branch for map ? _ ->  or x -> x ?
First, I do not want to reopen the disccussion about map and transform
One that cannot be expressed, intuitively _ -> !. That is the new construction
would return the sequence of the transformation of all matching elements.
> 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 ?
I think I was not clear. I do not want to eliminate transform, I want to eliminate
map but also the need to enclose virtually all the results of a tranform branch in [
]. (And call it map since is a more common name).
> 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.
I'm afraid that the frequent use of transform would make it a burden
> 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 ]
Just let me explain to the other users at cduce members that transform is inplemented by
a map + default branch + flatten, and that sequences are encoded by pairs
> 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.
This is quite a tempting solution, nevetheless I'm afraid that is can confuse the
programmer as then the meaning of
transform e with p1 -> [ e1 ] | p2 -> [ e2 e3 ]
would be exactly the same as the meaning of
transform e with p1 -> e1 | p2 -> [ e2 e3 ]
I cannot make up my mind
> 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".
The second seems better
More information about the Cduce-users