u. and v. Implicit Locatives for u and v
u. executes the verb named u using the namespaces that were in effect before the current explicit definition was called. The namespaces comprise the private namespace of the caller, if any, and the implied locale in effect in the caller. If the value of u contains names, these names will be found in the caller's namespaces.
u. is equivalent to u except that if you use u. in your modifiers, users will be able to call your modifiers with operands including privately-defined names.
u. and v. are called implicit locatives because (a) they do what locatives do, namely set a new execution environment, execute a name, and reset the environment; (b) the environment they switch to is the caller of the current function.
Allow a user-written modifier to accept locally-defined verbs from its caller.
haslocalfn =: 3 : 0 localfn =. +: (localfn exeu) y ) exeu =: 1 : 'u y' haslocalfn 10 NB. Tries to execute localfn in exeu where it is not defined |value error: haslocalfn | u y exeu =: 1 : 'u. y' haslocalfn 10 NB. Executes localfn in haslocalfn 20
- u. and v. are primitive verbs with infinite rank.
- The corresponding name must defined as a verb in the local namespace.
The local namespace must exist, i. e. u. and v. may not be executed from the console.
- u. and v. may be used in compounds, gerunds, etc.
- If the returned value of a modifier contains u. or v., u./v. will be replaced by its value.
This is because the returned value will be executed in the caller, where u./v. would not have the correct meaning.
- u. and v. can be passed as operands to another modifier, either bare or in compounds. Execution of u..v. in the called modifier will result in execution of each verb in its proper environment.
- u. and v. should not be passed as operands whose modifiers execute their operand as u and v (or x and y for very old modifiers). Such modifiers will execute the verbs in the wrong environment.
- If u. or v. appears in a verb whose value is fixed using f., u./v. is replaced by its value and the implied locative is lost.
- The environment in the caller is the environment that was in place when the sentence the caller is executing was started.
- u. and v. cn be used even in ordinary verbs if values have been given to u./v.. This can be used to execute arbitrary sentences in the caller's environment:
v =. 'coname' v. '' NB. get name of caller's locale v =. ". v. 'j' NB. get value of j in caller