Making an associative array with values having expression evaluation resultsAs usual I'm having trouble with Eval and Expr.
I need to create an associative array where values would be evaluated results of some expressions.
For instance I need to create
aaa=[
"2x2" => 4
]
but 4 there is a result of evaluated expression Expr(2*2)
Lame variant that obviously doesn't work is here:
aaa=[
"2x2" => 2*2
]
But then I'll say that 2*2 is an Expr:
aaa=[
"2x2" => Expr(2*2)
]
and then I'll use Eval Expr to evaluate all expressions inside the argument and return expression with evaluated subexpressions:
Eval Expr(
aaa=[
"2x2" => Expr(2*2)
]
)
and it already doesn't work - it doesn't evaluate Expr(2*2)
The next step would be to evaluate resultant expression:
Eval(
Eval Expr(
aaa=[
"2x2" => Expr(2*2)
]
)
)
but obviously it doesn't work.
Why does it not work and what is the correct way?
Sharing and Communicating ResultsRe: Making an associative array with values having expression evaluation resultsOk, understood. I thought that it was Associative Array specific, but looks like it is syntax specific 
Re: Making an associative array with values having expression evaluation results@Craige_Hales Good to know! Sounds like you have some behind-the-scenes development experience on this!
Re: Making an associative array with values having expression evaluation results
Why does it not work
The square bracket form is a compile time constant, both for arrays and associative arrays. The constant between the square brackets is cloned at run time and stored into aaa.
@ErraticAttack is the way I'd do it too.
Re: Making an associative array with values having expression evaluation resultsJMP is nothing if not inconsistent. You can do it via lists, which is what I do in these circumstances:
val1 = "Steve";
val2 = "The";
val3 = "Turtle";
aaa = Associative Array(
{"key1", "key2", "key3"},
Eval List( {val1, val2, val3} )
);
show( aaa )