J has no concept of block scope.  locales provide namespaces, so public assignments are not truly global but only visible within the locale; but for something small like what you are talking about you just can't do it.

Henry Rich

PS You CAN actually get to g's b from the function f, using a feature added within the last year.  But I'm not sure Ken would approve so I'm keeping it to myself.

hr

On 3/20/2020 5:59 PM, Rudolf Sykora wrote:
Dear list,


although I seem to be able to define a function within another function,
it seems that the inner function does not see private variables from the
outer one. What is then the correct way to write something like

g =: 3 : 0
b =. 2*y
f =. 3 : 'y-b'
f y
)

g 2

and get -2 as a result?

Here one can change b =. to b =: , but this makes b completely public,
and that's not particularly nice...


Thanks
Ruda.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


--
This email has been checked for viruses by AVG.
https://www.avg.com

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to