Question: Why does uneval behave differently in a procedure depending on a variable being local or global?

My question is based on this worksheet:

Consider the following procedure

myTest1 := proc()
     local s, gen;
     gen := proc()
          return 5;

     s := seq(['gen()', 'gen()', 'gen()']);
     return s;


If I call this procedure, myTest1(), the result is gen(),gen(),gen() printed out and then also returned from the procedure.

If I change local s to global s, the result changes to 5,5,5. That is, the sequence 5,5,5 is both printed and returned.


In the attached worksheet I have both cases that you can test.

Please Wait...