Copyright (c) 1989 1990, Roger K.W. Hui & K.E. Iverson Copyright (c) 1990 1991, Iversion Software Inc. All Rights Reserved. J Implementation Status (Version 3.4) Roger Hui 1991 7 15 NYA means not yet available Verbs: = self-classify equal < box less than <. floor lesser of (min) <: decrement less or equal > open larger than >. ceiling larger of (max) >: increment larger or equal _: NYA infinity NYA infinity + conjugate plus +. or/gcd +: double nor * signum times *. and/lcm *: square nand - negate minus -. not less -: halve match % reciprocal divide %. matrix inverse matrix divide %: square root root ^ exponential power ^. natural log log $ shape of shape ~. nub ~: nub sieve not equal | magnitude residue |. reverse (shift) rotate (shift) |: transpose transpose , ravel append ,. ravel items append items ,: itemize laminate ; raze link ;: words # tally copy #. base-2 value base #: binary rep. anti-base ! factorial out of /: grade up sort up \: grade down sort down [ same left ] same right { catalog from {. head take }. behead drop ". do (execute) do left if error (cond. execute) ": format format ? roll deal A. atomic rep. atom permute c. NYA characteristic NYA characteristic C. permute/cycle permute e. raze in in E. NYA search i. integers index of o. pi times circle p. NYA polynomial NYA polynomial 0: zero zero 1: one one Adverbs: m~ evoke evoke v~ both cross v/ insert table v/. oblique key v\ prefix infix v\. suffix outfix m} merge merge v} merge merge b. boolean boolean f. fix fix Conjunctions: u^:n power chain u^:v power chain u .v determinant inner product m : n defn defn m : 1 adverb m : 2 conjunction m : 11 tacit tacit m : v defn defn u : n defn defn u : v defn defn u :.v obverse obverse v;.n cut cut (NYA: v;.3 and v;._3) u!.n fit fit m!:n foreign foreign [. lev lev ]. dex dex m"n rank rank m"v rank rank u"n rank rank u"v rank rank u`v gerund g`:0 append append g`:1 until until g`:3 insert g`:4 recursion g`:5 selection u@v atop atop g@.v agenda agenda u@:v at at n&v with u&n with u&v compose compose u&.v under under u&:n appose appose Phrasal Forms: (u v) hook (u v w) fork n c adverb v c adverb c n adverb c v adverb Nouns: a. alphabet _ NYA infinity __ NYA negative infinity _. NYA indeterminate Pronouns: $. suite $: self reference x. first argument y. second argument xyz) label xyz: given names Copulae: name=.value local assignment name=:value global assignment noun=.value indirect local assignment noun=:value indirect global assignment System Limits: Array rank <: 127 Comparison tolerance <: 2^_34 Object size < 65536 bytes [PC only] Workspace size < 640 Kbytes [PC only] The !: Conjunction: The !: conjunction currently takes integer scalar left and right arguments, and derives verbs. (One exception: 5!:0 is an adverb.) These verbs behave like other verbs; in particular, they have intrinsic ranks, may be assigned names, and may serve as arguments to adverbs and conjunctions. Where these verbs take names as arguments (file names, WS names, or object names), the names are always boxed, and the verb rank is 0. As with all other verbs, verbs derived from !: requires one or two arguments. Some verbs have no "natural" arguments, but an argument must nevertheless be supplied (and will be ignored in execution). For example, timestamp =. 6!:0 6!:0 '' 1991 6 6 10 50 23 0!:0 Host System Command The string argument is forwarded to the host system for execution, and the result is returned as a string with embedded new-lines. For example: 0!:0 'dir *.exe' 0!:1 Spawn 0!:1 forwards its string argument to the host system for execution, like 0!:0, but the output (if any) is ignored. For example, 0!:1 can be used to invoke the vi editor on UNIX systems. 1!:0 Directory NYA 1!:1 File Read The argument is a boxed file name; the result is a string of the file contents. For example, 1!:1 <'dir\subdir\file.ext' The file name follows the conventions of the host system. The argument may also be the integer 1, meaning read from the keyboard. 1!:2 File Write xyz 1!:2 <':folder1:folder2:file' writes string xyz to the specified file. The right argument may also be the integer 2, meaning write to the screen. 1!:3 File Append string 1!:3 <'disk:folder1:folder2:file' 1!:4 File Size 1!:4 'dir/file1';'file2';'phile3' 1!:11 Indexed File Read The argument is a 2-element list of boxes: a file name and a 2-element integer list of the index and length. For example, 1!:11 'test';5 20 reads 20 bytes from file "test", starting from position 5. The index may be negative (the last byte of the file is index _1). The length may be elided, whence the file is read from the index to the end of the file. 1!:12 Indexed File Write The right argument is a 2-element list of boxes: a file name and an integer index. For example, xyz 1!:12 'test';14 writes (string) xyz to file "test", starting at position 14. The index may be negative (the last byte of the file is index _1). The positions to be written must already exist in the file (and the file must already exist). 1!:55 File Erase 1!:55 <'careful' 2!:0 WS Name Class The integer result is the name class (see 4!:0) of the object named in the boxed left argument, in the workspace named in the boxed right argument. In the following example, the result of the last sentence is 2 3 4. wsnc =. 2!:0 save =. 2!:2 noun =. i.3 4 adv =. / save <'wsname' ('noun'; 'save'; 'adv') wsnc <'wsname' 2!:1 WS Name List The sorted list of all names in the workspace named in the boxed right argument. 2!:2 WS Save Monad. Save all global definitions into the workspace named in the boxed right argument. The workspace is created if it does not already exist (and is overwritten if it already exists). Dyad. Save the global definition of the object named in the boxed left argument into the workspace named in the boxed right argument. If the object already exists in the saved workspace, it is overwritten; other objects in the saved workspace are unaltered. The workspace is created if it does not already exist. Workspaces are currently in WSIS format (see 5!:3), but may use a different format in future J versions. The workspace name follows the file naming rules of the host system, and it'd be a good idea to devise your own naming convention to distinguish workspaces from other files. 2!:3 WS PSave NYA "Protective" Save: like Save, but the monad does not modify an existing workspace, and the dyad does not overwrite objects already in the saved workspace. 2!:4 WS Copy Copy the object named in the boxed left argument from the saved workspace named in the boxed right argument, and define it as a global object. If the left argument is elided, all objects in the saved workspace are copied. Like all verbs, Copy applies to the argument cells in random order, so that if an object is copied from more than one workspace, the definition of the object could be from any of the workspaces. 2!:5 WS PCopy "Protective" Copy: like Copy, but does not overwrite objects already defined. 2!:55 WS Erase Erase the object named in the boxed left argument, from the workspace named in the boxed right argument. 3!:0 Internal Type The internal "type" of a noun, where 1 boolean 2 literal 4 integer 8 floating point 16 complex 32 boxed 3!:1 Convert to Internal Representation A string of the internal representation of a noun. The result is machine-dependent and may change in future J versions. 3!:2 Convert from Internal Representation Inverse of 3!:1, but nouns of type "boxed" will not be created. 4!:0 Name Class The argument is a boxed name; the result is its class: 0 undefined, but valid name 1 (not used) 2 noun 3 verb 4 adverb 5 conjunction 6 other 4!:1 Name List The argument is a subset of the integers from 2 to 5 (see 4!:0). The result is a list of boxed names belonging to the class(es) specified in the argument. The optional left argument are initial letters of the names of interest. 4!:55 Erase The object named in the boxed argument is erased. 5!:0 Fix 5!:0 is an adverb which defines an object from its atomic, display, or string representations. For example, fx =. 5!:0 ar =. 5!:1 ((ar <'a') fx) -: a =. i. 3 4 1 plus =. + $$ ar <'plus' 0 2 ((ar <'plus') fx) 4 5 6 7 If the argument is a boxed list of boxes, it is assumed to be an atomic representation (a result of 5!:1). NYA If the argument is a list of boxes, it is assumed to be a display representation (a result of 5!:2). If the argument is a string, it is assumed to be a catenation of string representations (results of 5!:3). The objects are defined, names embedded in the representation are assigned as a side effect, and the result of 5!:0 is the last represented object. 5!:1 Atomic Representation The argument is a boxed name; the result is a boxed list of two boxes uniquely representing the named object: noun: id value verb: id operator arguments adverb: id operator arguments conjunction: id operator arguments If an object is uniquely identified by the id alone (for example "a." or "+" or "/."), then the second field is elided, and the atomic representation is the id alone. Gerunds (results of the ` conjunction) are arrays of atomic representations. 5!:0 defines an object from its atomic representation. Atomic representations are sometimes called "canonical" or "boxed" representations. 5!:2 Display Representation The argument is a boxed name; the result is the display representation of the named object. 5!:0 defines an object from its display representation. (Different objects can have the same display representation, so 5!:0 is only a partial inverse.) f =. +/ . * f +-----+-+-+ |+-+-+|.|*| ||+|/|| | | |+-+-+| | | +-----+-+-+ each =. &. > (5!:2 <'f') -: (, each '+/') ; each '.*' 1 5!:3 String Representation The argument is a boxed name; the result is a string of the WSIS (Workspace Interchange Standard) representation of the named object. (See APL Quote-Quad, 1977 12; and SATN 22, IPSA.) 5!:0 defines an object from its string representation. The result of 5!:3 is a string, the catenation of the following parts: length Digits representing the length of the string representation (excluding the length itself). type One or two letters denoting the type of object c literal (character) array n numeric array xb boxed array xv verb xa adverb xc conjunction The string representation of a verb, adverb, or conjunction is the string representation of its opened atomic representation (the open of the result computed by 5!:0). name The name of the object, or "-" if anonymous. blank A single blank. rank Digits representing the rank. blank A single blank. shape Digits and blanks representing the shape. Each number in the shape is terminated by a blank. elements The ravelled elements. For a character or numeric array, this is the display form of the ravelled array; for a boxed array (hence for a verb, adverb, or conjunction), the elements themselves are recursively string representations. 5!:3 is subject to the fit conjunction &:, i.e. 5!:3&:d has d digits in the computed display form. With the possible exception of elements of literal arrays, the string representation contains only ASCII characters in the range 32 to 126 inclusive. 6!:0 Time-Stamp The current time as a 6-element list: year, month, day, hour, minute, and second (including any fraction thereof). 6!:1 Time since session start 6!:2 Time required to execute an expression 6!:2 '+/i.100' 6!:3 Delay (6!:3) 60 [ 'sleep for a minute' 7!:0 Space currently in use 7!:1 Space used since session start 7!:2 Space required to execute an expression 8!:0 (PC only) Query CGA mode (8!:0 ''){'non-CGA mode'; 'CGA mode' 8!:1 (PC only) Set CGA mode (8!:1) 0 [ 'set non-CGA mode' (8!:1) 1 [ 'set CGA mode' 8!:4 (PC only) Query screen attributes 8!:5 (PC only) Set screen attributes The argument is a 4 by 2 matrix of integer values between 0 to 15 inclusive. Attribute values conform to DOS conventions. .---------------------------. | input area | input area | | background | foreground | |-------------+-------------| | output area | output area | | background | foreground | |-------------+-------------| | cursor bar | cursor bar | | background | foreground | |-------------+-------------| | status line | status line | | background | foreground | |_____________|_____________| 8!:7 (PC only) Refresh screen Redisplay the contents of the screen. 8!:9 (PC only) Edit 8!:9 y invokes the editor on y, a string with lines delimited by linefeeds (10{a.). Press F1 to get meanings of function keys. 8!:16 (Macintosh only) Query font attributes 8!:17 (Macintosh only) Set font attributes Font attributes are a 3-element integer list of the font number, style, and size. "Style" is the sum of one or more of the following integers, where 1 Bold 2 Italic 4 Underline 8 Outline Font attributes can also be set by the font dialog box, invoked by the "Font ..." item under the "Edit" menu. 8!:19 (Macintosh only) Print screen 9!:0 Query random link 9!:1 Set random link. Default: 16807 9!:4 Query prompt 9!:5 Set prompt. Default: ' ' 9!:6 Query box drawing characters 9!:7 Set box drawing characters The argument is an 11-element string of nw,ts,ne, te,cr,tw, sw,tn,se, ns,ew (northwest corner, tee south, northeast corner; tee east, etc.) Defaults: [PC ] 218 194 191 195 197 180 192 193 217 179 196 { a. [Others] '+++++++++|-' 9!:8 Query error messages 9!:9 Set error messages For example: Replace English messages (default) with French ones. 9!:10 Query ) system command names 9!:11 Set ) system command names For example: Replace English command names (default) with French ones. Only the first 4 characters of each name are significant. 128!:0 QR decomposition The QR decomposition of a complex matrix in the domain of %. . The result is an Hermitian matrix and a square upper triangular matrix, individually boxed. 128!:1 Invert a square upper triangular matrix System Commands: )off Terminate session )si NYA )sic NYA )script Script )sscript Silent Script )script and )sscript accept an input file name and an optional output file name. File names must be in quotes. A dash (-) for the input file name means "standard input", i.e. the keyboard. The input file consists of lines of APL sentences and other input lines, and is known as a "script". The output file is suitable for subsequent use as a script. System commands in scripts are ignored. )script differs from )sscript in that it outputs to the "standard output" (the screen) as well as to any output file. Examples: )script - 'sesslog' Input obtained from the keyboard; output appended to file "sesslog" and to the screen. )sscript '\jscripts\asdf' Input from file "\jscripts\asdf"; no output. Input reverts to the keyboard at the end of "\jscripts\asdf". )sscript 'disk:folder:subfolder:inf' 'outf' Input obtained from "disk:folder:subfolder:inf"; output appended to "outf". )script - Default. If there is a file named "profile.js" in the current directory, J will automatically execute )script 'profile.js' at the start of a session. Command Line Parameter: (PC only) The command line parameter /s specifies standard input and standard output, without the session manager supplied with J. i.e. DOS command Effect j has session manager j /s standard i/o, no session manager Machines: AT&T 3B1 Apple Macintosh Atari ST DEC VAX (Ultrix and BSD UNIX) Interactive 386/ix IBM PC family: PC, XT, AT, 286, 386 IBM RISC/6000 MIPS R3000 NeXT Philips P9070 Silicon Graphics SGI Irix Sun 3 Sun 386i Sun 4 (SPARC) Changes between Version 2, 1990 8 9 (APL90 Version) and Version 2.7, 1990 10 22 J code size reduced slightly alternatives for national use characters = faster monad -. faster dyad ~. faster ~: faster monad ,. faster ;: rhematic rules re . and : changed e. faster i. faster dyad . cum (gerund from verb) : con (verb from gerund) :: faster u"v rank (like u, but has ranks of v) u&.v under =. indirect local assignment =: indirect global assignment 3!:2 convert from internal representation 5!:0 fix 5!:1 atomic representation 8!:0 8!:1 query/set CGA mode 9!:0 9!:1 query/set random link 9!:4 9!:5 query/set prompt 9!:6 9!:7 query/set box drawing chars 9!:8 9!:9 query/set error msgs 9!:10 9!:11 query/set ) system command names )box removed )prompt removed )reset renamed )sic )rl removed )script profile facility added ATARI ST ported to tutorial faster Changes in Version 2.8, 1990 11 15 ": faster on boxed arrays display faster on boxed arrays 5!:0 string representation inverse 5!:3 string representation 8!:2 8!:3 removed (replaced by DOS facility) 8!:4 8!:5 set screen attributes 8!:7 refresh screen )clear removed (equivalent to 4!:55 (4!:1) 2 3 4 5 ) PC simplified session manager PC added command line parameter /s Changes in Version 2.9, 1991 2 15 +: monad added *: monad added -: monad added ": dyad added 0: added 1: added m&g f&n faster :: labels adverbs n c, v c, c n, c v derive adverbs 2!:0 WS name class 2!:1 WS name list 2!:2 WS save 2!:4 WS copy 2!:55 WS erase 8!:9 (PC) Edit 8!:16 8!:17 (Mac) query/set font attributes 8!:19 (Mac) print screen Macintosh improved user interface PC improved user interface 386ix ported to SGI ported to Changes in Version 3, 1991 3 17 [ previously spelt }: ] previously spelt {: . previously spelt .. ` previously spelt . `: previously spelt : : previously spelt :: +/\ invertible -/\ invertible */\ invertible %/\ invertible =/\ invertible ~:/\ invertible +/\. invertible -/\. invertible */\. invertible %/\. invertible =/\. invertible ~:/\. invertible ^~ invertible ,~ invertible ;~ invertible ,:~ invertible |:&:k shift b. boolean m. mean n. normalize s. standard deviation xyz: given names tab treated like space on input Mac resizeable Language Summary Changes in Version 3.1, 1991 5 17 LinkJ m : 1 replaces 1 : m m : 2 replaces 2 : m m : 11 translate to tacit 1!:11 indexed file read 1!:12 indexed file write m. redefined n. redefined s. redefined u . v determinant Changes in Version 3.2, 1991 6 2 A. previously spelt @: C. previously spelt @. !. previously spelt &: ,. ravel items / append lists ; raze / link @. agenda @: at &: appose f. fix [. lev ]. dex m. removed n. removed s. removed proverbs dynamic reference 0!:1 documentation updated Changes in Version 3.3, 1991 6 25 ,. ravel items / append items 0-frames corrected a-trains implemented c-trains implemented PC help screens updated Changes in Version 3.4, 1991 7 15 NB. implemented National Use implemented (Appendix A of dictionary)