While this (x__1_) could be done, it would also violate some current locality guarantees -- code using it would become difficult to understand.
A more robust approach would be to define a nested block mechanism for J, but even that needs a clear definition of why it's useful (but it's most useful where clarity is remote). -- Raul On Mon, Feb 11, 2013 at 10:16 AM, Don Guinn <[email protected]> wrote: > You cannot nest close parens like ends in Pascal and PLI; however, this > works: > > f=:3 : 0 > g=.3 : '3+y' > 2*g y > ) > f 4 > 14 > > Notice that the y's in f and g are unique. > > As you already know, this does not work: > > f=:3 : 0 > g=.3 : 0 > 2*g y > ) > 3+y > 4 5 6 > ) > |syntax error > | ) > |[-5] > > The problem here is that the definition of g does not occur until f is > executed. So the "3 : 0" is not done until it's too late. > > This works too: > > f=:(3 : 0) (1 : 0) > 2*u y > ) > 3+y > ) > f 4 > 14 > > Here both definitions are performed when f is defined. > > There have been times I wanted to access local names defined in the caller. > Doesn't work. But they could be passed as arguments. Not pretty. > > A possible way could be to extend locales to have negative locale numbers > which refer to the names in callers. Like "abc__1_" would access "abc" of > the caller. And "y__2_" would refer to the right argument of the caller's > caller. > > On Mon, Feb 11, 2013 at 6:51 AM, Alex Giannakopoulos < > [email protected]> wrote: > >> Don Guinn wrote: >> > Also, the x and y in explicit definitions are local names so are unique >> > from x and y of a calling explicit definition. That includes recursion. >> >> Yes, I am aware of that, but what if I have a nested function, that is >> local to another, enclosing function? >> Is that even possible in J? I couldn't write one there were problems >> with the terminating 'close bracket' >> ) >> >> But assuming I could write it: What if I want to refer to the >> "parent's" x-value in the definition of an enclosed function/verb? >> Like a free variable in Lispy languages. >> Do I have to copy and rename it first, inside the enclosing scope? >> Sounds a bit clunky. >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
