
Hello, I'm currently trying to grasp the way proto trasnform are supposed to work and I was wondering fio there is any use cases or examples of how and why a Visitor can be used. Thanks

Joel Falcou wrote:
Hello,
I'm currently trying to grasp the way proto trasnform are supposed to work and I was wondering fio there is any use cases or examples of how and why a Visitor can be used.
Hi, In the proto/v4 branch, "Visitor" has been renamed "Data" to more accurately reflect its role as a blob of user-specified data to be passed along to each transform. A very simple example is a lambda library with placeholders. Imagine you wrote a transform that evaluated lambdas with arguments. When evaluating a lambda expression such as (_1 + _2) with the arguments (3,4), you might pass the arguments to the transform as a tuple in the Data parameter (a.k.a Visitor). Then, when the transform has recursed to a placeholder terminal, say _1, the result would be the 0th element in the Data tuple. I have reimplemented the Boost Lambda Library on top of proto using this technique. You can find it here: http://svn.boost.org/trac/boost/browser/branches/proto/v4/libs/proto/example... HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler a écrit :
In the proto/v4 branch, "Visitor" has been renamed "Data" to more accurately reflect its role as a blob of user-specified data to be passed along to each transform. OK so my first intuition was right then ;)
A very simple example is a lambda library with placeholders. Imagine you wrote a transform that evaluated lambdas with arguments. When evaluating a lambda expression such as (_1 + _2) with the arguments (3,4), you might pass the arguments to the transform as a tuple in the Data parameter (a.k.a Visitor). Then, when the transform has recursed to a placeholder terminal, say _1, the result would be the 0th element in the Data tuple.
Doesn't this features make context obsolete ? I mean instead of using context to traverse the AST and performs evalmuations, oen can simply build a proper visitor and traverse the AST in a way simialr to a classic visitor pattern ?
I have reimplemented the Boost Lambda Library on top of proto using this technique. You can find it here:
I'll get a look. Seems alos that I missed the v4 branches. Is there large changes between this and the last proto zip that was available ont he vault ? Two other questions : - why does trasnform apply deep copy onto terminals ? - I'm currently using proto to implement some parallel programming library and I have to explain what I do with proto to people more used to the classic compilation/semantic vocabulary than to the proto idioms. in this context, is it correct to say that transforms are "semantic actions" applied onto the element of the AST ?

Joel Falcou wrote:
Eric Niebler a écrit :
A very simple example is a lambda library with placeholders. Imagine you wrote a transform that evaluated lambdas with arguments. When evaluating a lambda expression such as (_1 + _2) with the arguments (3,4), you might pass the arguments to the transform as a tuple in the Data parameter (a.k.a Visitor). Then, when the transform has recursed to a placeholder terminal, say _1, the result would be the 0th element in the Data tuple.
Doesn't this features make context obsolete ? I mean instead of using context to traverse the AST and performs evalmuations, oen can simply build a proper visitor and traverse the AST in a way simialr to a classic visitor pattern ?
Yes, in proto v4 contexts are not necessary. They can, in some circumstances, be easier to work with then transforms, so I don't plan to remove them. They may even be better at compile time.
I have reimplemented the Boost Lambda Library on top of proto using this technique. You can find it here:
I'll get a look. Seems alos that I missed the v4 branches. Is there large changes between this and the last proto zip that was available ont he vault ?
There are non-trivial changes, yes. Most significantly, the protocol for implementing custom transforms has changed. Also, a bunch of functions and types have been renamed as a result of review feedback.
Two other questions : - why does trasnform apply deep copy onto terminals ?
Not sure what you mean. Can you give an example?
- I'm currently using proto to implement some parallel programming library and I have to explain what I do with proto to people more used to the classic compilation/semantic vocabulary than to the proto idioms. in this context, is it correct to say that transforms are "semantic actions" applied onto the element of the AST ?
Absolutely. A proto transform *IS* a semantic action. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Yes, in proto v4 contexts are not necessary. They can, in some circumstances, be easier to work with then transforms, so I don't plan to remove them. They may even be better at compile time. Make sense indeed. It may solve my other problem then. I need to perform SIMD computation onto my matrix element. For scalar, proto provided the appropriate overload for let's say +,-,*,/ and so on. I think hat using visitor may solve the problem of selecing the proper form of operation on the fly.
There are non-trivial changes, yes. Most significantly, the protocol for implementing custom transforms has changed. Also, a bunch of functions and types have been renamed as a result of review feedback. So, I better change now and adapt my code ? How can the v4 be downloaded ?
Not sure what you mean. Can you give an example? I had the impression that terminal helds value by reference until it get transformed and turne dinto value.
Absolutely. A proto transform *IS* a semantic action. Ok then, the arguments are clear now :)
-- Joel FALCOU Research Engineer @ Institut d'Electronique Fondamentale Université PARIS SUD XI France

Oh and while I'm at it : is there any publications concerning proto I can cite in academics bibliography ? -- Joel FALCOU Research Engineer @ Institut d'Electronique Fondamentale Université PARIS SUD XI France

Joel FALCOU wrote:
Oh and while I'm at it : is there any publications concerning proto I can cite in academics bibliography ?
Yes, for a link to a published paper about Proto, see the "further reading" section at the bottom of: http://boost-sandbox.sourceforge.net/libs/proto/doc/html/boost_proto/preface... AFAIK, the proceedings for LCSD'07 hasn't been published by the ACM yet, so I'm not sure how you would reference this paper. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Joel FALCOU wrote:
Yes, in proto v4 contexts are not necessary. They can, in some circumstances, be easier to work with then transforms, so I don't plan to remove them. They may even be better at compile time. Make sense indeed. It may solve my other problem then. I need to perform SIMD computation onto my matrix element. For scalar, proto provided the appropriate overload for let's say +,-,*,/ and so on. I think hat using visitor may solve the problem of selecing the proper form of operation on the fly.
I'm not sure how the data parameter figures here. Wouldn't the semantic action be conditioned on the expression type? E.g., when an expression is a binary +, do the binary + action. For that, you'd just use a proto grammar decorated with transforms, and not involve the data parameter at all.
There are non-trivial changes, yes. Most significantly, the protocol for implementing custom transforms has changed. Also, a bunch of functions and types have been renamed as a result of review feedback. So, I better change now and adapt my code ?
Better IMO to wait until v4 is finished and committed to trunk.
How can the v4 be downloaded ?
It's in boost's subversion repository under the branches/proto/v4 directory.
Not sure what you mean. Can you give an example? I had the impression that terminal helds value by reference until it get transformed and turne dinto value.
You can certainly write a transform that turns terminal references into
values, but that's not the default behavior.
Consider the following program that promotes int terminal to longs and
leaves all others as-is:
#include <cstdio>
#include
Absolutely. A proto transform *IS* a semantic action. Ok then, the arguments are clear now :)
-- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler a écrit :
I'm not sure how the data parameter figures here. Wouldn't the semantic action be conditioned on the expression type? E.g., when an expression is a binary +, do the binary + action. For that, you'd just use a proto grammar decorated with transforms, and not involve the data parameter at all.
Yeah I kinda brainstormed a bit further. What I have now is the following. I construct an AST with a simple grammar with no transform. Then I use a transform that turn the AST into a tuple containing the pointer to each matrix data int he AST. Then i use another transform to compute if the AST is "SIMDizable" aka every terminal is a matrix of the same type and this type has a SIMD equivalent. If this is true, then I apply another transform that turn all SIMDizable node into their SIMD version (basically repalcing proto::tag::plus for ex. into my_lib::tag::simd::plus) and evaluates it with a visitor which references the data tuples.
Better IMO to wait until v4 is finished and committed to trunk. *nods*
You can certainly write a transform that turns terminal references into values, but that's not the default behavior. The example is indeed valuable I can see my former error now. Thanks for the head up.
-- Joel FALCOU Research Engineer @ Institut d'Electronique Fondamentale Université PARIS SUD XI France
participants (3)
-
Eric Niebler
-
Joel Falcou
-
Joel FALCOU