Trace it out. (By the way, you have a syntax error in your eval statement. There is no + after float)
You first call calc with an argument:
This turns calc into the code below. Notice how statement is now "1+2".
Code:
global proc calc ("1+2")
{
float $res = eval("float $_dummy = " + "1 + 2");
print ("\n" +$statement +"=" +$res);
}
MEL then takes the two strings in eval, and makes them into one.
Code:
global proc calc ("1+2")
{
float $res = eval("float $_dummy = 1 + 2");
print ("\n" +$statement +"=" +$res);
}
The eval statement is then evaluated. This essentially does the following in the background. res holds the resultant value of the eval command. In this case, since you created a variable, it returns the value of the variable.
Code:
global proc calc ("1+2")
{
float $_dummy = 1 + 2;
float $res = $_dummy;
print ("\n" +$statement +"=" +$res);
}
So when it gets to the print command, it prints out the statement that was given, "1+2", then an equal sign, then the result of the eval command, which is 3.
Imagination is more important than knowledge.