) a. i. s The character with index 10 marks the end of each line 121 46 42 37 58 121 46 10 58 10 120 46 42 33 121 46 10 Boxed and table representations of a script s may be obtained as follows: ]b=. <;._2 s Cut on the final fret and exclude the frets õýýýýýýýÃýÃýýýýýýÀ þy.*%:y.þ:þx.*!y.þ ÁýýýýýýýÂýÂýýýýýýã ]t=. >b y.*%:y. : x.*!y. Any one of these representations r may be used as the right argument to the explicit definition conjunction to produce an adverb (1 : r), conjunction (2 : r), or verb (3 : r). The left arguments 11-13 produce equivalent results, but in tacit form if possible. For example: f=. 3 : s f 9 The colon in the script separates the monadic and dyadic cases 12 3 f 4 The x. and y. refer to the left and right arguments 72 The phrases a=. 1 : 0 and c=. 2 : 0 and v=. 3 : 0 provide direct entry of adverbs, conjunctions, and verbs. Files of scripts may define functions and other entities that can serve to supplement the primaries of J. They are commonly refered to as secondary or tertiary functions according to their relative generality. H. LOCATIVES The name abc_def_ is called a locative, and is said to refer to abc in locale def. For example: b=. 1 Rome=. 2 Rome_NewYork_=. 20 f_NewYork_=. 3 : '3*b=: Rome+y.' f_NewYork_ 10 90 b,Rome 1 2 b_NewYork_ 30 A locale holds and references names without conflicting with names in other locales. A script file can be used to populate a locale. For example, if the file stats contains the following script: mean=. sum % # sum=. +/ then: exec_a_=. 0!:11 Do exec in locale a exec_a_ <'stats' Populate locale a mean=. sum % # sum=. +/ mean=. 34 mean_a_ 3 4 5 4 sexec_a_=. 0!:10 Silent execution sexec_a_ <'stats' The name f_abc_ is executed in locale abc in the sense that any name referenced in f is sought therein. If f does not occur in abc, it is inheritedáfrom the special locale z, but is executed in the child locale abc. The name f in the base locale (as in f or f__) is treated similarly. Specifically: 1. A named entity is evaluated in the indicated locale (or in the base locale if the name is not full). 2. An expression in a script file is evaluated in the locale that it serves to populate. 3. All other expressions are evaluated in the base locale. Defining or expunging a name in a child locale does not affect definitions in the parent locale, and inherited names do not occur in the namelist of a child. Defining f_abc_ does, of course, override the use of an inherited name in subsequent use of the name f_abc_. For example: mean_stats_=. +/ % # mean_z_ =. # %: */ mean_stats_ 4 5 6 7 Arithmetic mean 5.5 mean_z_ 4 5 6 7 Geometric mean 5.38356 centre_z_=. - mean centre_z_ 4 5 6 7 _1.38356 _0.383563 0.616437 1.61644 centre_stats_ 4 5 6 7 _1.5 _0.5 0.5 1.5 Scripts are commonly used to populate a locale with secondary and tertiary functions that supplement the primaries of J. I. ERRORS AND SUSPENSION Execution of a sentence suspends when an error occurs, and an error message and context information are then displayed. Four blanks indicate where parsing stopped. Suspension may occur in immediate execution, in the execution of a script file, or in the execution of an explicitly defined function, as illustrated by the following examples: Immediate execution 2+'a' |domain error | 2 +'a' Execution of a script file t=. '2*3',(10{a.),'2+''a''',(10{a.),'2+3' t A script 2*3 2+'a' 2+3 t 1!:2 <'test' Write script file 0!:11 <'test' Execute script file 2*3 6 2+'a' |domain error | 2 +'a' |[-1] | 0!:11<'test' 2+3 5 Explicitly defined function g=. 3 : ('1+y.' ; ':' ; '2+x.+y.') 3+g 'a' |domain error | 1 +y. |g[0] | 3+ g'a' f=. 3 : '1+g y.' f 'a' |domain error | 1 +y. |g[0] | 1+ g y. |f[0] | f'a' Sentences can be executed in the suspended environment, local values can be accessed, and execution can be resumed. The cases of the foreign conjunction used to control suspension are assigned convenient names by execution of the script file debug.js as follows: dbr=. 13!:0 Reset stack and disable (0) or enable (1) suspension dbs=. 13!:1 Display stack dbsq=. 13!:2 Stop query dbss=. 13!:3 Stop set dbrun=. 13!:4 Run again dbnxt=. 13!:5 Run next dbret=. 13!:6 Exit and return dbjmp=. 13!:7 Continue at line number specified by argument Each function requires a right argument, which is ignored except in the cases of dbr, dbss, dbret, and dbjmp. Errors do not cause suspension unless debugging (invoked by the phrase 13!:0 (1)) is in effect. When suspension is in effect, the input prompt is six spaces. Explicit stops are requested by name and line number in the argument of dbss, which contains zero or more stop specifications separated by semicolons. Each stop specification indicates a function name, line numbers for the monadic case, and (following a :) line numbers for the dyadic case. An asterisk indicates all lines. For example: dbss 'f 0' NB. f monadic line 0 dbss 'f :2' NB. f dyadic line 2 dbss 'f 0 2:1' NB. f monadic 0 2, dyadic 1 dbss 'f 0;g 1' NB. f monadic 0 and g monadic 1 dbss 'f *:*' NB. f all monadic and dyadic dbss '* 0:0' NB. all monadic 0 and dyadic 0 dbsq '' NB. query stops * 0:0 dbr 1 f=. 3 : 0 10 11 12 : 20 21 22 ) dbss=. 13!:3 dbss 'f 1' f '' þstop þ 11 þf[1] þ f'' DEFINITIONS Each main entry in the body of the dictionary is headed by a line beginning with the informal name of the monadic case of the function, and ending with the informal name of the dyadic case. The line also contains the formal name of the function, consisting of one character or two, the last of which is a period or colon. In the case of a conjunction, the formal name is preceded by m or by u (denoting a noun or a verb argument) and is followed by n or v. An adverb has no symbol to its right. The three ranks (in the order monadic, left, and right) are also indicated, using the symbol _ for an infinite (unbounded) rank, and with ranks dependent on the ranks of argument verbs shown as mu, lv, etc. Examples are provided with each definition, and the more complex of them may use auxiliary functions as yet unfamiliar. These examples may be approached by ignoring all but the immediately relevant aspects of such auxiliaries, and by examining (and perhaps entering for execution) component phrases that can be used to build up the final result bit-by-bit. For example, in the discussion of the adverb / , the sentences below display various uses of it for convenient comparison: x=. 1 2 3 4 5 [ y=. 7 5 3 (,.x);(x+/y);y;(x*/y);(+/y);(*/y) õýÃýýýýýýýÃýýýýýÃýýýýýýýýÃýýÃýýýÀ þ1þ 8 6 4þ7 5 3þ 7 5 3þ15þ105þ þ2þ 9 7 5þ þ14 10 6þ þ þ þ3þ10 8 6þ þ21 15 9þ þ þ þ4þ11 9 7þ þ28 20 12þ þ þ þ5þ12 10 8þ þ35 25 15þ þ þ ÁýÂýýýýýýýÂýýýýýÂýýýýýýýýÂýýÂýýýã Even if the auxiliary functions ; and ,. are unfamiliar, their relevant effects are probably evident; if not, they may be clarified by the following experiments: x;y ,.7 8 $,.7 8 õýýýýýýýýýÃýýýýýÀ 7 2 1 þ1 2 3 4 5þ7 5 3þ 8 ÁýýýýýýýýýÂýýýýýã Although a name (such as foreign for !:) is suggested for each word, others can be used in addition to or instead of them. Thus, joy might be used for ! since the exclamation mark derives from an I placed above an o, an abbreviation of the Latin io. Similarly, iota might be used instead of integersáand index of for i.. Self-classify = _ 0 0 Equal =y classifies the items of the nub of y (that is, ~.y) according to equality with the items of y, producing a boolean table of shape #~.y by #y. For example: y=. 3 3 $ 'abcdef' y ; (~.y) ; (=y)õýýýÃýýýÃýýýýýÀþabcþabcþ1 0 1þþdefþdefþ0 1 0þþabcþ þ þÁýýýÂýýýÂýýýýýã x=y is 1 if x is equal to y, and is otherwise 0. The comparison is made with a tolerance t, normally 2 to the power _44 but also controlled by the fit conjunction !., as in x=!.0 y. Formally, x=y is 1 if the magnitude of x-y do es not exceed t times the larger of the magnitudes of x and y.Tolerance applies similarly to other verbs as indicated for each, notably to Match (-:), to Floor (<.), and to Signum (*), but not to Grade (/:). Both the monadic and dyadic cases of the verb = apply to nouns of any rank, and to boxed as well as simple nouns. For example: ]a=. ;: 'Try and try and try again.'õýýýÃýýýÃýýýÃýýýÃýýýÃýýýýýýÀþTryþandþtryþandþtryþagain.þÁýýýÂýýýÂýýýÂýýýÂýýýÂýýýýýýã ~. aõýýýÃýýýÃýýýÃýýýýýýÀþTryþandþtryþagain.þÁýýýÂýýýÂýýýÂýýýýýýã =a a= <'and'1 0 0 0 0 0 0 1 0 1 0 00 1 0 1 0 00 0 1 0 1 00 0 0 0 0 1Because of the limited precision of the computer, results which should agree (such as 1 44*(13%144) and 13) may not; the tolerant comparison allows the comparison of it with 13 to show agreement (a result 1). More or less stringent comparisons may be made by using the conjunction !. to specify a tolerance t, as in the functioneq=. =!.t. Copulas (Is) =. Local =: Global The copula is used to assign a referent to a name, as in a=.3 and in sum=.á+/. The copula =. is local as discussed under Explicit Definition (:), and =: is global. For example: f=. 3 : 0 a=. +:y. b=: *:a 10*b ) a=. b=. 678 a,b 678 678 f 3 360 a,b 678 36 Copulas may also be used indirectly. For example: ]x=. 'abc';'de' õýýýÃýýÀ þabcþdeþ ÁýýýÂýýã (x) =. 3 4 ; 5 6 7 abc 3 4 de 5 6 7 'abc'=. i.3 a 0 b 1 c 2 Note that the parentheses around the name x force it to be evaluated before the assignment specified by the copula is effected. Box < _ 0 0 Less Than . xa 2 0 0 3 5 0 7 11 13 The cut has several uses (chosen by the right argument). For example: box=. < ;. _1 t=. '/i sing/of olaf/' box t õýýýýýýÃýýýýýýýÃÀ þi singþof olafþþ ÁýýýýýýÂýýýýýýýÂã The display of a boxed array would normally be corrupted by control characters (such as carriage returns and linefeeds) occurring within it; in the display they are replaced by spaces. For example, try < 8 32 $ a. Floor (Integer Part) <. _ 0 0 Lesser Of (Min) <.y gives the floor or integer part of y, that is, the largest integer less than or equal to y. For example: <. 4.6 4 _4 _4.64 4 _4 _5The implied comparison with integers is tolerant, as discussed under Equal (=), and is controlled by <.!.t. See McDonnell [11] for the treatment of complex arguments. x<.y is the lesser of x and y. For example: 3 <. 4 _43 _4 <./7 8 5 9 22 <./\7 8 5 9 27 7 5 5 2 The floor applied to the argument increased by one-half gives the nearest integer: ]x=. 2 + 3 %~ i. 2 5 2 2.33333 2.66667 3 3.33333 3.66667 4 4.33333 4.66667 5 x + 1r2 2.5 2.83333 3.16667 3.5 3.83333 4.16667 4.5 4.83333 5.16667 5.5 <. x + 1r2 2 2 3 3 3 4 4 4 5 5 The number of digits needed to represent an integer is given by one plus the floor of its base ten logarithm. For example: logs=. 10 ^. a=. 9 10 11 99 100 101 ((6.3&":);<.;(1: + <.)) logs õýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýÃýýýýýýýýýýýÃýýýýýýýýýýýÀ þ 0.954 1.000 1.041 1.996 2.000 2.004þ0 1 1 1 2 2þ1 2 2 2 3 3þ ÁýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýýÂýýýýýýýýýýýÂýýýýýýýýýýýãâââ– The floor <. y is equivalent to ->.-y. In other words, it is the dual of ceiling with respect to (that is, under) arithmetic negation: <.&.- is equivalent to >. and >.&.- is equivalent to <. For example: ((>.&.-);(<.)) 4.6 4 _4 _4.6 õýýýýýýýýýÃýýýýýýýýýÀ þ4 4 _4 _5þ4 4 _4 _5þ ÁýýýýýýýýýÂýýýýýýýýýã Decrement <: _ 0 0 Less than or Equal <:y is y-1. For Example: <: 2 3 5 7 1 2 4 6Also see Not (-.) x<:y is 1 if x is less than or equal to y, and is otherwise 0. See Equal (=) for a discussion of tolerance. See Equal (=) for a definition of tolerance. The fit conjunction applies to <: . The inverse of <: is >: (increment). For example: n=. 5 <: ^: _1 n 6 <: ^: _1 >: <:^: 0 1 2 n Here ^: applies to a noun right argument (0 1 2) 5 4 3 <: ^: i. n Here ^: applies to a verb right argument (i.) 5 4 3 2 1 */ <: ^: i. n 120 f=. */ @ (<: ^: i.) f n 120 f"0 i. n 1 1 2 6 24 (f"0 = !) i. n 1 1 1 1 1 Open > 0 0 0 Larger Than Open is the inverse of box, that is, >áy is 1 if x is tolerantly larger than y. See Equal (=) for a discussion of tolerance. For example: 1 2 3 4 5 > 5 4 3 2 10 0 0 1 1 Tolerance t is provided by >!.t. Since the rank of open is 0, it applies to each atom of its argument. For example: ]a=. 1 2 3;4 5 6;7 8 9 õýýýýýÃýýýýýÃýýýýýÀ þ1 2 3þ4 5 6þ7 8 9þ ÁýýýýýÂýýýýýÂýýýýýã >a 1 2 3 4 5 6 7 8 9 Results of different shapes are padded as defined in Section II B. For example: (>1;2 3;4 5 6);(>'a';'bc';'def');(<\i.4);(><\i.4) õýýýýýÃýýýÃýýýýýýýýýýýýýýýýýýýýýÃýýýýýýýÀ þ1 0 0þa þõýÃýýýÃýýýýýÃýýýýýýýÀþ0 0 0 0þ þ2 3 0þbc þþ0þ0 1þ0 1 2þ0 1 2 3þþ0 1 0 0þ þ4 5 6þdefþÁýÂýýýÂýýýýýÂýýýýýýýãþ0 1 2 0þ þ þ þ þ0 1 2 3þ ÁýýýýýÂýýýÂýýýýýýýýýýýýýýýýýýýýýÂýýýýýýýã Ceiling >. _ 0 0 Larger Of (Max) >.y gives the ceiling of y, that is, the smallest integer greater than or equal to y. Thus: >. 4.6 4 _4 _4.65 4 _4 _4The implied comparison with integers is tolerant, as discussed under Equal (=), and is controlled by >.!.t. See McDonnell [11] for the treatment of complex arguments. x>.y is the larger of x and y. For example: 3>.4 _44 3 >./7 8 5 9 29 >./\7 8 5 9 27 8 8 9 9 The comparison x = >. x determines whether x is an integer. Thus: Integer_test=. ] = >. See the definition of fork in Section II F. Integer_test 3 3.14 _5 1 0 1 f=. = >. The same function may be defined by a hook. f 3 3.14 _5 1 0 1 The ceiling >. y is equivalent to -<.-y. In other words, it is the dual of floor with respect to (that is, under) arithmetic negation: >.&.- is equivalent to <. and <.&.- is equivalent to >. . For example: