
Eric Niebler <eric@boost-consulting.com> writes:
I hope Eric can find the time to review it and maybe add it to the boost::proto examples. I would certainly have benefited from something like this being available. On the other hand, I've learned more by doing it. Thanks to Eric for having helped me and for making boost::proto available.
<snip code>
I have no comments about your use of proto -- it looks a lot like the lazy_vector example from the users' guide, in fact.
Another difference, again probably obvious to the seasoned user, but that the average newcomer might miss is that in order to allow an assignment of the form: int v = ...expr involving extended types... you seem to need an operator int () in the wrapping expression. That was the best I managed to do and the only reason I needed to wrap boost::proto expressions in my example. If there's a better way, I'd like to know. The lazy vector example doesn't show anything of sort. The nearest is the line: double d1 = (v1 + v2)[2] but there the double comes from the evaluation of operator[]. I still think that an example on lightweight DSLs, where you're not drastically change domain, but what you need is almost plain C++ expression would be useful. The example I posted shows how to wrap a UDT and how to slightly modify the semantics of a few operators. The next example I'm working on will show how to define multiple version of these and control what can be mixed with what (and furthemore define the type of the result when they mix together). Again, small things, but having a cookbook of these may be very helpful to newcomers to proto. I think that the effort it takes to people to understand concepts can be minimized by moving from the territory they know up in reasonably small steps. A big-bang example showing the mighty of proto is very good for catching the attention and convincing people that investing time in proto is worthwhile, but then it is important not to lose them off the learning curve. I'll keep posting what I'm learning with your help. I hope boost.devel is the right place, as boost::proto has not been officially included in boost yet and this is probably where early adopters hang around. Maurizio