I have an
Association which is the result of an intensive computation. Its values include the variable
x and I would like to turn the entire
Association into a set of
I could use a
Delayed Definition (Reference) using the
:= function (
SetDelayed). However, this would redo the initial computation every time, which is inefficient. I prefer using an
Immediate Definition using
= for the
Function. However, that does not seem to work.
The following Mathematica code illustrates the problem:
f1[x_]=Association["linear"->x, "square"->x^2]; f1["square"] (* x^2 *) f2[x_]:=Association["linear"->x, "square"->x^2] f2["square"] (* 9 *)
Function f1 does not produce the desired result, whereas f2 does. How can I obtain the desired result? If possible, please explain the underlying theory, such that I will be able to tackle such problems myself in the future.