The problem if you do it with globals or global namespace is reusability (which you may not care about).
if you run myFun twice with two different buttons (lets say you want to be able to sandbox your window and run two instances of it). You'll have collision and the second call will override the firsts.
See below.
names default to here(1);
new namespace("test");
test:myFun = Function({A1, Z1},{Default Local},
test:A = A1;
test:Z = Z1;
test:A[2] = 10;
test:B = 2*test:A;
show(test:A);
show(test:B);
show(test:Z);
//::g_b = b;
//::g_z = z;
test:nw = new window("test",
vlistbox(
textbox(test:Z),
textbox(char(test:B)),
buttonbox("Show array B (works)",
show(test:B)
),
buttonbox("Show string Z (works)",
show(test:Z)
),
buttonbox("show and close (works)",
show(test:Z, test:B); test:nw << closewindow())
)
)
);
x = [2,3];
y ="string";
test:myFun(x,y);
test:myFun([12, 14], "something else");
if you're using a namespace, I recommend using the window namespace. It automatically deletes when the window is gone and you won't have collision between two identical windows.
names default to here(1);
myFun = Function({A1, Z1},{DEFAULT LOCAL},
A = A1;
Z = Z1;
A[2] = 10;
B = 2*A;
show(A);
show(B);
show(Z);
//::g_b = b;
//::g_z = z;
nw = new window("test",
window:B = B; //uses the builtin window namespace
window:Z = Z; //works because this is a glue statement that returns the last thing
window:box = vlistbox( //which in this case is the vlistbox
textbox(window:Z),
textbox(char(window:B)),
buttonbox("Show array B (works)",
show(window:B)
),
buttonbox("Show string Z (works)",
show(window:Z)
),
buttonbox("show and close (works)",
show(window:Z, window:B); window:box << closewindow())
)
);
);
x = [2,3];
y ="string";
myFun(x,y);
myFun([12, 14], "something else");