A simple question. I have looked at the help pages on "passing" and "declaring" arguments, which are very detailed, but couldn't quite spot the answer to my question, though I suspect it is there somewhere.
I have 2 procedures and want to pass the argument of one procedure to another procedure used therein. In the basic case, I seem to be able to do it without special precautions. However, I have not been able to make it work in a situation involving multiple spellings for the arguments (except of course by selecting a different spelling for each of the procedures). An example should suffice to clarify what I mean.
In the first case below, I pass the argument n of procedure f1 to procedure f2. No problem.
restart;
f1:=proc(n::posint:=1)
return f2(n);
end proc;
proc(n::posint := 1) ... end;
f1();
f1(2);
f2(1)
f2(2)
f2:=proc(n::posint:=1)
return n^2;
end proc;
proc(n::posint := 1) ... end;
f1();
f1(2);
1
4
In the second case below, I use multiple spellings for the argument, either n or N, and as a result call the procedure with the argument 'n'=1, say, that is g1('n'=1) instead of simply f1(1) above. And this causes problems in the call to the second procedure g2 inside the first procedure g1, because since the n has been assigned to the value 1 (not sure that "assigned" is the right word, but you will know what I mean) the procedure receives g2(1=1) instead of the desired g2('n'=1). I tried a few things like writing g2('uneval(n)'=n) or back-quotes, but that didn't help.
restart;
g1:=proc({[n,N]::posint:=1})
return g2('n'=n);
end proc;
proc({[n, N]::posint := 1}) ... end;
g1();
g1('n'=2);
g1('N'=2);
g2(1 = 1)
g2(2 = 2)
g2(2 = 2)
g2:=proc({n::posint:=1})
return n^2;
end proc;
proc({n::posint := 1}) ... end;
g2();
g2(2);
g2('n'=2);
1
1
4
g1();
g1('n'=2);
g1('N'=2);
1
1
1
Of course a simple workaround is to give up multiple spellings and have, say, g1('n'=1) and g2('N'=n). But surely there's a simple way to do this?
Related question, is there a way to define a procedure with multiple spellings, say g2 above, to accept both g2(2) and g2('n'=2) as syntax? (wouldn't that then fix the problem?)
Thanks.