Boost logo

Proto :

Subject: [proto] How to prevent function to be called for every evaluation of an expression?
From: Ole Svensson (o.svensson_at_[hidden])
Date: 2013-08-16 03:43:09


Hi,
 
for educational purposes I am implementing an EDSL for vector arithmetic and lazy evaluation which works quite nice (and fast) so far. But when I compile something like:
 
Vector a, b, c;
a = b + c + dotProduct(b, c);
 
the result is computed correctly but dotProduct() is called for every component of the vector which is clearly undesirable. I thought of solving this by using transforms to pre-evaluate scalar-valued sub-expressions but when I call
proto::display_expr( b + c + dotProduct(b,c) );
the AST that is printed does not include some kind of function node but the return value of dotProduct(b,c) -- i.e., some number.
 
So my questions are:
a) Why is dotProduct(b,c) still evaluated for every component and
b) how can I prevent this from happening for *every* scalar-valued function? (I.e., I do not want to declare *specific* functions as terminals in my DSL.)
 
Many thanks and best regards
Ole
 

Proto list run by eric at boostpro.com