Assign by reference or by value. Where is the documentation?

February 06 2012 by tjoff 5
false
Maple 15

1


Today, after hours of hunting a persistent bug in a worksheet, I discovered something i did not know about Maples evaluation strategy. Consider the following Maple code:

restart:
a:=1:
b:=a:
b:=2:
a;

Now the variable 'a' holds the value of 1. Now consider the case where 'a' is a vector:

restart;
a:=<1,1>:
b:=a:
b(2):=2:
a;

What would you expect the value of 'a' to be?
If you expected <1,1> like me, you are wrong, 'a' is <1,2>.

So in the first example assignment seems to be by value, whereas in the second it seems to be by reference. This behaviour seems unintuitive and inconsistent to me, and the difference in behaviour is not documented under the "The assignment Statement" section of Maple Help.

Since assignment is such a fundamental operation, I assume that the behaviour is intentional, and not a bug. Or what? Or can anyone here explain the rationale for this behaviour, and point me to the documentation ?

 
Loading Comments & Answers

You must be logged into your MaplePrimes account in order to post a comment. If you don't have an account, you can create an account here.

     

Forgot Your Password? Create an Account