>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  Primer

Global

A name defined outside the execution of a verb is a global name.

In the previous section, the t1 defined in the ijx window is a global name that is completely different from the t1 defined inside the verb centigrade.

Let's try some experiments. Create a temporary script file with File|New ijs and type into it the definition:
fooa =: 3 : 0   NB. =: is important
zzz + y
)
Run the script with Run|Window. In the ijx window:
   fooa 5
|value error
|       zzz+y
Let's define the global zzz to see what happens. Defining it outside a verb means it is a global. In the ijx window:
   zzz =. 23	NB. define global zzz
   fooa 5
28
The verb fooa uses the global zzz. So, a verb can use globals.

Edit the script to add foob and then run the script.
foob =: 3 : 0
zzz =. 7
zzz + y
)
In the ijx window:
   foob 3
10
   zzz
23
The verb foob uses its local zzz and ignores the global. So, a verb can use locals and ignore globals of the same name.

Inside a verb the copula =. defines a local name. Once a name is defined as a local, references to that name are to the local name.

What if you wanted to define a global name? The global copula =: (= with a colon inflection) defines a global name. Edit the script to add fooc and then run the script.
fooc =: 3 : 0
gw =: y
lz =. y
)
In the ijx window:
   fooc 3
3
   gw
3
   lz
|value error
   gw =. 24
   fooc 5
5
   gw
5
Defining gw with =: defines the global name.

In general, it is good practice to only define locals in a verb and to not define globals. This is an important part of what is sometimes called a functional style of programming. Verbs that define globals are said to have side effects and are more likely to cause bugs and make it harder to read the application to understand what is happening.

It is possible to define a verb that uses both the global and local definitions of a name and this is VERY bad practice.

>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  Primer