From J Wiki
Jump to navigation Jump to search

=. (Is (Local)) Noun/Other

>> <<   Back to: Vocabulary Thru to: Dictionary

Is (Local) =. performs private assignment. A name that is privately assigned is visible only to the explicitly-defined entity that defined the name.

=. used outside of an explicit definition has the same effect as =: .

   'fe fi__ fo fum'=. i.4  NB. Outside explicit definition: names are public
   fe ; fi ; fo ; fum
   foo=: verb define
fe=. 90          NB. private, holds true only while foo runs
fi__=. 91        NB. locative, overwrites in locale
fo=: fe+fi       NB. public; =: overwrites the original value of fo
fum=. 1&+        NB. holds true only while foo runs (fum is now a verb)
fum y            NB. Execute fum; its result is the result of foo
   foo 999
NB. Only fi__ and fo have changed (as result of running: foo)...
   fe ; fi ; fo ; fum

Note that the load verb, which loads scripts, is explicitly defined, so any privately-assigned names in a script will disappear when the script has finished loading.

WARNING: value here can be other than a noun value. Thus a verb defined in a script using =. instead of =: will disappear once the script has finished loading.

Detailed Description

When an explicitly-defined entity starts running, a private namespace is created for it. Assignments to simple names using =. define names in the youngest private namespace. Names in the youngest private namespace hide other variables of the same name.

Only the youngest private namespace is active. Older ones are ignored until all younger have been destroyed. When an explicit definition exits, its private namespace is destroyed along with all its names, and the youngest surviving namespace is activated.

Private assignment is not used for locatives, which are always public in their locale. When there is no private namespace (i. e. when no explicitly-defined entity is running), =. performs public assignment, just like =:.

=. supports simple assignment, indirect assignment, multiple assignment, and AR assignment just as =: does.

Common uses

Used where other languages would employ a local variable.

See Also