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

My question is based on this worksheet: uneval.mw

Consider the following procedure

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

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

end;

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.

Why?

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

Please Wait...