Boost logo

Boost :

Subject: Re: [boost] [GSoC][Phoenix3] Regarding mutability of arguments passedto phoenix expressions
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-04-27 19:37:57


----- Original Message -----
From: "Thomas Heller" <thom.heller_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, April 27, 2010 9:49 PM
Subject: [boost] [GSoC][Phoenix3] Regarding mutability of arguments passedto phoenix expressions

>
> Regarding arguments to phoenix expressions there are two possibilities.
> The first is: Arguments are mutable. The current phoenix is implemented to be
> able to this.
> Example:
>
> int i( 1 );
> ( ++phoenix::arg_names::arg1 )( i );
>
> The result of ++phoenix::arg_names::arg1 will be 2, i will have the value 2
> after the expression is evaluated.
>
> The other approach would follow a more functional programming style as the
> data will not be mutable
>
> int i( 1 );
> [1] ( ++phoenix::arg_names::arg1 )( i );
> [2] ( ++phoenix::arg_names::arg1 + phoenix::arg_names::arg1 )( i );
>
> The result of [1] will be 2, however i does not get changed (it remains to be
> 1).
> The result of [2] will be 3. i still unchanged.
> This example would be working "out-of-the-box" with the current prototypes.
> To get the mutability back into phoenix i propose the use of phoenix::ref.
>
> I favor the second approach. However, this would break API compatibility
> between the existing implementation.
> The question i want to ask the current and prospective users if it feasible to
> break your existing code? Is there a lot of existing code depending on this
> behaviour? Does it make sense to break code in such a way?

Hi,
Even if Phoenix has not been released yet on Boost, I don't think that breaking code will be desirable.

I don't know very well Phoenix, but I think that if you use inmutable functions you will get what you want

If I dont want to change i I will write instead of [1,2]
int i( 1 );
[3] ( phoenix::arg_names::arg1 + 1)( i );
result==2
i==1
[4] ( phoenix::arg_names::arg1 + 2)( i );

So if you don't want to change your parameter don't use functions that change it.

I'm not saying that your approach is not the correct one, but in order to avoid break code what do you think to define inmmutable arguments as a different class and use ref to get mutability?

Best,
_____________________
Vicente Juan Botet Escribá
http://viboes.blogspot.com/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk