From J Wiki
Jump to: navigation, search

1B. Locales And The Loading Of Script Files

The phrases for each section are contained in the subdirectory system\examples\phrases in the J system. They can be loaded as illustrated below:

   load 'system\examples\phrases\phrd1.ijs'
1 : 'i. by i. over x./~@i.'

   * bft 4
| |0 1 2 3|
|0|0 0 0 0|
|1|0 1 2 3|
|2|0 2 4 6|
|3|0 3 6 9|

For most use this load into the base locale is satisfactory. However, in any joint use of phrases from different sections it must be remembered that the names m0, m1, etc., are unique only within each section. Distinct names can be assigned by loading the files into distinct locales, perhaps using the letter that denotes the section followed by the number that denotes the chapter. For example:

   'a2' load 'system\examples\phrases\phra2.ijs'
	The file for Section A of Chapter 2

   m67_a2_ 0 1
0 0.841471

|value error
   sin_a2_ 0 1
0 0.841471

Any names may be used for locales, but the use of majuscules will avoid conflict with those (such as j) used by the utilities. Simpler names may also be assigned at will, as in

   q=: m67_a2_

For a screen display of any group of phrases (complete with comments), use the file read. Thus:

   y=: 1!:1 <'system\examples\phrases\phra1.ijs'
n0=: i. 6               NB. List of first six non-negative integers
m1=: ^&3                NB. Cube
m2=: mean=: +/ % #	NB. Arithmetic mean
d3=: $,:		NB. x copies of y
m4=: <.@(0.5&+)		NB. Round
m5=: =+	        	NB. Test for real number
m6=: (<0 _1)&C.	        NB. Swap leading and final items
m7=: +/\  -: +/\.&.|.   NB. Prefix sum scan is suffix under reversal