In what order are wave names evaluated within commands?

Hi all,

I can find a go-around to this problem, but I'd like to understand Igor better for the future.

I recently wrote a function called "rotMatrix" that takes in an axis number "axis" (1->x, 2->y, 3->z) and an angle "theta" as arguments, and generates a rotation matrix that rotates by theta around the specified axis. To make my code more compact, I had the function store the result in a matrix called "rotMatrixResult"; at the end of the function I returned the name of this matrix, so that I could do this:

$(rotMatrix(1, pi/2)) evaluates to...
$("rotMatrixResult") evaluates to...
rotMatrixResult

Thus, $(rotMatrix(1, pi/2)) returns the wave in which I've stored the result.

Here is my problem: When I try to run a command with MULTIPLE $(rotMatrix) calls, like

MatrixMultiply $(rotMatrix(1, pi/2)), $(rotMatrix(2, pi/4)), $(rotMatrix(3, pi))

I'm not sure which results stored under "rotMatrix" Igor is using. Before moving on to the second wave argument, does Igor evaluate the first wave to "rotMatrixResult", or does it actually evaluate until it knows the contents of the wave?

That is, does Igor evaluate like this:

MatrixMultiply $(rotMatrix(1, pi/2)), $(rotMatrix(2, pi/4)), $(rotMatrix(3, pi)) ->
MatrixMultiply {{...}{...}{...}}, $(rotMatrix(2, pi/4)), $(rotMatrix(3, pi)) ->
MatrixMultiply {{...}{...}{...}}, {{...}{...}{...}}, $(rotMatrix(3, pi)) ...

resulting in three different matrices? Or like this:

MatrixMultiply $(rotMatrix(1, pi/2)), $(rotMatrix(2, pi/4)), $(rotMatrix(3, pi)) ->
MatrixMultiply rotMatrixResult, $(rotMatrix(2, pi/4)), $(rotMatrix(3, pi)) ->
MatrixMultiply rotMatrixResult, rotMatrixResult, $(rotMatrix(3, pi)) ...

resulting in the same matrix three times?

(And if it's the second way, is there some other way to make my code this compact? I thought it was a very beautiful solution until my code stopped working :/)
I can't answer your question, except to suggest that the fact that your code fails probably indicates that your second scenerio is the correct one. You might make your matrix rotation function return a wave with a uniquely named wave... see UniqueName function in the online help. If you don't do it already, you might also have the matrix rotation function create FREE waves so they go away when the code is finished using them and you don't have to do any other cleanup.
jtigor wrote:
You might make your matrix rotation function return a wave with a uniquely named wave... see UniqueName function in the online help. If you don't do it already, you might also have the matrix rotation function create FREE waves so they go away when the code is finished using them and you don't have to do any other cleanup.


Thanks so much! I hadn't heard of either of those Igor features, that helps a lot.