You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Fabrizio Morbini <fm...@gmail.com> on 2010/08/12 20:51:54 UTC

[scxml] double evaluation of expr in assignments

Hi,

problem: i would like to assign to a variable, v1, the value of
another variable, v2, but the name "v2" is the result of an
expression. For example, assume you have an inspect event that should
assign to a predetermined variable the value of the variable whose
name is passed as payload to the inspect event.

attempted solution: add a new parameter to the scxml assign action.
The new parameter is a boolean that if true allows to evaluate the
result of the first evaluation of the expr field of the assign action.
In the example above, if the expr is
"_eventdatamap.get('inspect').get('varName')" the first evaluation
will return "v2" the second evaluation will return the value of "v2"
in the datamodel.

question: this seems a common situation and i wonder if there is
already a solution.

thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [scxml] double evaluation of expr in assignments

Posted by Rahul Akolkar <ra...@gmail.com>.
On Thu, Aug 12, 2010 at 2:51 PM, Fabrizio Morbini <fm...@gmail.com> wrote:
> Hi,
>
> problem: i would like to assign to a variable, v1, the value of
> another variable, v2, but the name "v2" is the result of an
> expression. For example, assume you have an inspect event that should
> assign to a predetermined variable the value of the variable whose
> name is passed as payload to the inspect event.
>
> attempted solution: add a new parameter to the scxml assign action.
> The new parameter is a boolean that if true allows to evaluate the
> result of the first evaluation of the expr field of the assign action.
> In the example above, if the expr is
> "_eventdatamap.get('inspect').get('varName')" the first evaluation
> will return "v2" the second evaluation will return the value of "v2"
> in the datamodel.
>
> question: this seems a common situation and i wonder if there is
> already a solution.
>
<snip/>

The above is like a gensym operation (generate symbol) and there isn't
a standard solution. As you point out, its possible to do this with a
variant of the assign action.

Depending on the expression language and data structures, you can get
some "pseudo-gensym" behavior (for example, when using JEXL you may
generate the key for a map using an expression within the [ ]
operator). In SCXML, the underlying datamodel context is itself like a
map, but it isn't exposed directly to the expressions as such.

-Rahul


> thanks
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org