Boost logo

Proto :

Subject: Re: [proto] Manipulating an expression tree
From: Eric Niebler (eric_at_[hidden])
Date: 2011-04-08 04:35:30


On 4/8/2011 3:28 PM, Karsten Ahnert wrote:
>> (Please don't top-post. Rearranging...)
>
> Hmm, I just used reply in my mail client. (Sorry for this double)
>
>>> Another question is: can a node have a state. In my algorithm it would
>>> be nice, if every proto::multiplies< > node stores some intermediate
>>> values which are used during later evaluations of the tree.
>>
>> No. Intermediate expression nodes carry no run-time state in their
>> nodes. They only carry compile-time information in the form of the tag.
>> That's how a plus node is distinguished from a minus node, for instance.
>>
>> If you need to compute intermediate values, you can use a transform to
>> build a parallel structure.
>
> Do you mean to build an entire new tree, or just to replace some nodes?

If only some nodes have associated intermediate result, then you could
just replace some nodes.

> In my current algorithm I use callable contexts to do the work. I think
> this is more favorable since I have to evaluate the tree N times to obtain
> the result.

Why does that matter? Transforms are almost always a better choice.

> I think it would be nice to replace some nodes and customizing
> the evaluation context, such that these nodes can be used to store the
> intermediates.

If you're doing calculation *and* tree transformation, then drop the
callable contexts. They can't do the job.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Proto list run by eric at boostpro.com