I have been trying to understand Maple's evaluation rules for arguments or parameters as they are passed through procedures, but I am getting confused. Here is an example:

p1 := proc( y )  print( y, 'y', eval(y,1), eval(y,2) ) :  p2( y ) :  end proc :
p2 := proc( z )  print( z, 'z', eval(z,1), eval(z,2) ) :  end proc :

x := ''''5'''' :
print( x, 'x', eval(x,1), eval(x,2) ) :

p1( x ) :

So a variable x is assigned, then passed to the procedure p1, and inside p1 it is passed to the procedure p2. The output of the first print (for x) is ''5'', x, '''5''', ''5''. As I understand it, the assignment x := ''''5'''' evaluates the right hand side, which removes one layer of quotes. Then print( x ) evaluates its arguments, removing the second layer of quotes. Also the procedure call p1( x ) evaluates its arguments, which also removes the second layer of quotes. At this point then, inside p1, the variable x has the value ''5''.

The output from p1 is ''5'', ''5'', ''5'', '5'. The output from p2 is the same as from p1, and presumably it would be the same if we had even more nested procedures. This is where I get confused (of course I might be confused already). Inside p1, print( y ) evaluates its arguments? And inside p1, the procedure call p2( y ) evaluates its arguments? Following my reasoning, the output from p1 would be '5', etc., and the output from p2 would be 5, etc.. Can someone tell me what I am missing?

What I find even more confusing is that print(y) and print('y') both give ''5'' with two quotes. Following my reasoning, print('y') would have one more layer of quotes than print(y).

I am already (somewhat) familiar with the concepts of full evaluation and one-level evaluation, etc. As I understand it, Maple uses full evaluation outside procedures, and one-level evaluation for parameters and local variables inside procedures. But I still can't figure out what is going on in this example.

 


Please Wait...