First of all, note that locale is a very different word from local, even though there is only one less letter in the latter.
A locale is a set of global names. There can be several locales, so there can be several sets of globals.
A global name in a locale is distinguished from the same name in other locales by qualifying the name with the addition of the locale name bracketed by _ (underbar) characters. A name qualified by a locale is always a global name.
abc_def_ =: 2
The above sentence can be read as global abc in locale def is 2.
abc_base_ =: 4
The above sentence can be read as global abc in locale base is 4.
If the locale name is elided, it is assumed to be base.
abc__ NB. the same as abc_base_
If a global name is not qualified with a locale name, then it is in the current locale. The base locale is the current locale unless it has been explicitly changed by executing a verb in a different locale. The following defines abc in the base locale:
abc =. 6
Since the base locale is the current locale, the names abc and abc_base_ are the same.
The name abc_def_ is clearly different from abc, but so far there is no way of telling that anything special is going on. In what sense are abc and foo in the same (base) locale? And abc and abc_def_ in different locales?
One way of distinguishing is to use the names utility verb that lists global names.
a =. 23
b =. 24
a_q_ =. 25
w_q_ =. 26
names 0 NB. 0 lists nouns
a abc b
Your names result may be different, but it will include all global nouns you have defined in the base locale. You should see the a and b that you defined above and note that you do not see the w that was defined in locale q.
To see the names defined in locale q you can do the following:
names_q_ 0 NB. names in locale q
Nouns a and w are defined in the q locale.
Locales partition global names into different sets, and utilities, such as names, can work with globals in a particular locale.
The real power of locales comes into play with verbs defined in a locale. When a verb executes in a locale it executes with that locale, not the base locale, as the current locale.
Let's define a simple verb in the q locale to see how this works.
f_q_ =. 3 : 'a =: y'
This verb defines global a with its right argument. There can be many different locales, each with their own global a. But when f_q_ executes, it executes in the q locale and the q locale is the current local, and global names it uses are from the q locale. Try the following experiments:
a =. 23 NB. define a in the base locale
a_q_ =. 24 NB. define a in locale q
f_q_ 100 NB. execute f in locale q
Executing f_q_ 100 defined global a_q_ as 100. It did not affect the global a in the base locale.
If a verb explicitly references a name in a locale then that is the global that is affected. For example, define verb g_q_ that defines a in the base locale. You will see that the a in the base locale is defined and the a in the q locale is not changed:
g_q_ =. 3 : 'a_base_ =: y' NB. explicit locale name
Locales partition global names into separate sets. In particular, related nouns and verbs, say in a set of utilities, can be defined in their own locale. Their names don't conflict with names in the base or other locales. When you look at your application you can look at just the related globals that are in a particular locale. When a verb runs in a locale it uses globals from that same locale.
The names verb with an argument of 0 lists nouns, with 3 it lists verbs, and with 6 it lists locale names.
names_q_ 3 NB. verbs
names 6 NB. locale names
base j q z
The list of locale names is interesting. base and q you know about, but what about j and z ?
The globals in the j and z locales are defined when J starts up and runs the profile.ijs script. The j locale contains things which are useful in building an application and is discussed in the J Online Documentation.
The z locale is very interesting indeed.