cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
New to using JMP? Hit the ground running with the Early User Edition of Discovery Summit. Register now, free of charge.
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
miguello
Level VI

Making an associative array with values having expression evaluation results

As 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?

 

 

 

4 REPLIES 4
ErraticAttack
Level VI

Re: Making an associative array with values having expression evaluation results

JMP 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 )
Jordan
Craige_Hales
Super User

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.

Craige
ErraticAttack
Level VI

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!

Jordan
miguello
Level VI

Re: Making an associative array with values having expression evaluation results

Ok, understood. I thought that it was Associative Array specific, but looks like it is syntax specific