From: Eric Niebler (eric_at_[hidden])
Date: 2007-05-20 16:26:35
Maurizio Vitale wrote:
> I know you've already stated you feel proto::or_ and proto::and_ are the
> right names. And if it wasn't for trying to solve the naming conflicts
> with the MPL I wouldn't have any issues with this choice.
> But I'll try anyhow.
> What about following Haskell (from the list prelude, not pattern handling) and
> having proto::or_ become proto::any and proto::and_ become proto::all?
> This would free the present names for the other changes.
Heh, I almost called proto::_, the wildcard pattern, proto::any.
Regardless, any<> and all<> are not bad, but I see a few problems:
1) any<> doesn't suggest that alternates are tried in order
2) Neither suggest short-circuiting
3) You haven't said what proto::if_ and proto::not_ should be.
(3) is the killer. Taken together, and_, or_, not_ and if_ give users an
expressive and intuitive framework for reasoning about their grammars.
Changing just "and_" and "or_" to "all" and "any" would break the symmetry.
>  actually I have a fundamental problem with 'or_' (and 'any') as they both focus on one
> part of what they do: certainly the pattern matches if any of the component patterns match.
> What they fail to convey is that the _first_ pattern that matches is used for further
> processing, like evaluating the result of a transform.
True. Many of the types in proto have 2 and sometimes 3 roles. For
instance, proto::plus<> is:
- An expression generator. (proto::plus<A,B>::type is the type of a plus
node in an expression tree, where A and B are the types of the children
- A pattern. (proto::plus<A',B'> matches the expression generated by the
above if A' and B' are patterns that match A and B, for instance.)
- A transform. (proto::plus<A',B'>::apply< E, S, V >::type will apply a
pass-through transform to E, with S state and V visitor.)
If_ and not_ also have default "identity" transforms. Even proto::expr<>
can be used as a pattern (it matches itself) and as a transform (the
> But I cannot come up with a name that describe these two facets satisfactorily, so I guess
> documentation will have to supplement the name.
I don't think it's a problem.
> And now that I think of it, I have no clue of what a transform with a proto::and_ at the
> toplevel would do. Time to look at docs/source code I guess.
By default, proto::and_ applies the transform of the last branch that
matches, just as proto::or_ applies the transform of the first branch
that matches. It's somewhat arbitrary, I admit, but I've found this a
-- Eric Niebler Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk