Vocabulary/ZeeLocale

From J Wiki
Jump to navigation Jump to search

Back to: Vocabulary

"Factory words": the z-locale and its contents

J does not have "reserved words" as such. On the other hand certain "factory" J words (nouns, verbs, adverbs or conjunctions) come shipped with the product.

You can rely on a subset of these words being always present (unless deliberately erased or redefined by some action you take).

The J Dictionary says: "It is convenient to supplement the primitives or primaries provided in a language by secondaries whose names belong to an easily recognized class."

This recognises the fact that some J words are to be considered part of the J language.

For instance, words like LF, load, each, require and exit.

Alas, there is no universal agreement on precisely which words these are. However they all reside in the z-locale.

Important.png Full documentation of the contents of the z-locale is now available in:

(J User Guide) Standard Library Documentation


What is the z-locale and why is it important?

Here's where the J Primer explains what a locale is. And here's what the J Primer has to say about the z-locale.

It follows from these explanations that the z-locale is the ideal home for a J word that is to behave as if it's really part of the J language. But not all the words in the z-locale can properly be called secondaries of the J language. Some words are not defined until you require them to be present:

   plot_z_
|value error: plot_z_

   require 'plot'

   plot_z_
3 : 0
caller_jwplot_=. coname''
'' plot_jwplot_ y
:
caller_jwplot_=. coname''
x plot_jwplot_ y
)

Where do the words in the z-locale come from?

The z-locale is populated when J is started up.

The core set of words, such as LF, load, names and open, are defined in a script: stdlib.ijs -- the so-called standard library.

  • In J602, stdlib.ijs carries full information on the usage of each verb in the form of comments preceding each definition.
  • In J803, stdlib.ijs has been stripped of comments and isn't very informative.

Refer instead to (J User Guide) Standard Library Documentation.

View this script by:

   open 'stdlib'   NB. in J602
   open '~system/main/stdlib.ijs'   NB. in J803

In J602 stdlib.ijs resides in the folder: ~system/main/. Find its full pathname on your computer by:

   jpath '~system/main'
/Applications/j602/system/main

(J's response will vary.)

In addition, strings.ijs generally also gets loaded (into the z-locale) by default. It resides in the same folder as stdlib.ijs.

View this script by:

   open 'strings'

Additionally, several packages and add-ons define one or more words in the z-locale, to let you run them easily from within any locale, without needing to know the locale(s) where they actually reside.

Example: the plot package:

   conames''
0           2           base        j           jgl2
jijs        jregex      jzgrid      lint        rgsdatetime
tte         z           zulu
   load 'plot'
   conames''   NB. note the extra locale names that appear...
0           2           base        j           jafm
jbmp        jgl2        jijs        jregex      jwplot
jzgrid      jzplot      lint        rgsdatetime tte
z           zulu
   plot_z_
3 : 0
caller_jwplot_=. coname''
'' plot_jwplot_ y
:
caller_jwplot_=. coname''
x plot_jwplot_ y
)

Such cover verbs are often very simple ones:

   jpath_z_
jpath_j_

Where can I read details of a given word in the z-locale?

Open the script in which you know the word is defined (say: deb).

In J602, the verb edit will help you:

   edit 'deb'

In later J versions, edit may not be defined. In that case, try to find the script that loaded deb by:

   (4!:3'') {~ 4!:4 <'deb'
+------------------------------------------+
|/Applications/j602/system/main/strings.ijs|
+------------------------------------------+

If the above phrase works, then so will this:

   open (4!:3'') {~ 4!:4 <'deb'

Can I define my own words in the z-locale?

Yes, freely.

But be careful not to accidentally overwrite a word already there:

   myedit_z_
|value error: myedit_z_
   NB. --okay, it's not already there

Just define it as you would in the base locale, but make your name a locative by appending _z_ to your chosen name:

   myedit_z_ =: 3 : 'open (4!:3'''') {~ 4!:4 boxopen y'
   myedit 'deb'

Which words in the z-locale can I rely on being there for my client?

This is a hard call.

Some words you expect to find in jqt801.app (say) may be absent in jcons801.app (say).

wd for instance.

There is no substitute for starting up the actual J version your client will be using, and verifying the presence (and definition!) of the words you hope s/he'll find.

First make sure that your startup script is either absent or empty:

You may have favorite private words defined which other users won't possess.

   open '~config/startup.ijs'

In j602 the Project Manager will build you a script containing all the "factory" words your project needs.