Question: question on returning table from function

I wanted to overwrite an existing variable of type table by the one returned from a call to a proc().

But it does not work, unless eval() is called on the returned result from the proc()

But if the variable that recieves the return value from the proc() was not already a table type, then it works without using eval. Why is that? 

Here is an example

restart;
foo:=proc(A::table)
  A["c"]:=3; #add new field
  return A;
end proc;

A:=table():
A["a"]:=1:
A["b"]:=2:
B:=foo(A):
whattype(B);
print(B)

           table(["a" = 1, "c" = 3, "b" = 2])

In the above, it worked. is table now, and assigned the updated table from the proc.  But 

A:=table():
A["a"]:=1:
A["b"]:=2:
A:=foo(A): #without eval, it does not work.
whattype(A);
print(A)

             symbol
               A

I expected A to be overwritten, just like B was. To fix this, I have to change A:=foo(A): by A:=eval(foo(A)):

But why eval was not needed in the first example, and was needed for the second example?

btw, the same thing happens with Record(), not just table()

just like to understand the reasoning behind this. I expected both cases to work the same way. But it works different if the variable happend to be unassigned (like B above).

Please Wait...