Essays/JAspects

From J Wiki
Jump to: navigation, search

Aspects of J to be aware of

Context

  • A J session operates in a "workspace" of definitions and values
  • A session may use one or more windows for entry and output display
  • A session window record may be saved for future reference
  • Data values may be saved between sessions only by explicit action
  • Program-operation definitions are copied to and from script files
  • Script files may be prepared with the J editor or any other
  • Except in definition mode, each line is interpreted after entry
  • Formatted results may be captured from screen or written externally

Syntax

  • Each statement must be contained on a single line
  • On any line, text following symbol NB. is commentary
  • Empty lines are acceptable
  • Brackets, braces, commas, and semicolons do not delimit groups
  • Period and semicolon also appear in names of many J symbols
  • Numbers must show a digit before any decimal point
  • Negative numbers are preceded by a "low minus" (underscore)
  • Names, symbols, and values may be separated by 0 or more blanks
  • Numbers must be separated from any following unrelated letter
  • Numbers may be decimal, rational, exponential, extended precision
  • Complex numbers may be specified, either Cartesian or polar
  • Stored character values may contain any character in set (a.)
  • Character literal in expression may not contain newline or return
  • Lists of numbers are separated/joined by blanks, not commas
  • A number list following a (rank) number needs a separator
  • Operations apply to number lists without need for parentheses
  • Mere succession of computed values does not specify a list
  • All operations expect one data value argument on the right
  • Many operations also accept or require a data argument on the left
  • A named program is activated via the same syntax as for symbols
  • Arguments may be atomic or arbitrarily structured as needed
  • A verb must be supplied some argument value to be executed
  • A symbol with only a right argument will be interpreted monadically
  • Presence also of a left argument will cause dyadic interpretation
  • There are no execution precedences among fundamental operations
  • Parentheses enclose expressions to be evaluated before others
  • In a multi-operation expression, the right-most evaluates first
  • Evaluation results are substituted in the remaining phrase
  • Modifying adverbs and conjunctions do have "precedence" over verbs
  • Conjunctions and/or parentheses can form new compound operations
  • Conjunctions are required for most non-standard noun-verb sequences
  • Multiple-verb sequences are evaluated by hook and/or fork rules
  • A user-defined value or operation name must start with a letter
  • A name may contain mixed-case letters, digits, embedded underscore
  • A name ending with a tag between underscores belongs to that locale
  • An ending tag following a double underscore is a variable locale
  • No legal user-definable names are reserved for system use
  • Defining a name used in another loaded script may cause confusion

Data structure

  • Every data value in J is an array
  • Every array has a rank of 0 (atom), 1 (list), 2 (table), or more
  • A positive-rank array is stored as a list of lower-rank "items"
  • Every array has a rectangular shape--the sizes of successive axes
  • Each array is of one type--numeric, character, boxed, or symbol
  • Every array has a level (or box depth) of 0 or more
  • Arrays of rank 2 or higher cannot be entered literally
  • Lists may be constructed with Append, Link, etc.
  • Tables may be constructed with Stitch, Laminate, Table, etc.
  • Sub-arrays may be rotated at any rank level
  • Array axes may transposed into any order
  • Arrays of level 1 or higher cannot be entered literally
  • The Box of an array creates an atom of level one greater
  • The Open of an array may be of one level less, but never negative
  • The Open of an array will be of the greatest rank found
  • The Open of a box array will fail when it finds mixed data types
  • A box value is always distinct from and unequal to its Opened form
  • "Symbol" values are character strings beginning with ` (accent grave)
  • Symbol values may be created, structured, stored, selected, matched
  • Specified elements or sub-arrays may be copied from an array
  • Consecutive head or tail elements may be selected along any axis
  • Consecutive head or tail elements may be omitted from a copy
  • Elements may be selected along an axis by index, possibly multiple
  • Indices for an n-element axis always run 0 through n-1 (0 origin)
  • Indices _1 through -n run backward from the end of the axis
  • Elements may be selected from box at any level by specifying path
  • An array may be copied with specified substitutions (Amend)
  • An expression evaluating to data value may be stored as a named noun
  • A named array may be modified only by total replacement (Is)
  • Any axes of an array may have length 0--an empty array
  • Reducing axis length by Drop, even to 1 or 0, does not reduce rank
  • Selecting with n atoms of index yields subarray of rank n lower
  • Array with a single item (singleton) is not an atom if positive-rank
  • A singleton may be accepted as an atom or may give unwanted result
  • Leading axes of length 1 are not apparent on printing
  • The shape of a character array with many blanks may not be apparent
  • Distinguishing between character and numeric is difficult in boxes
  • The rank and shape of an empty value may not be apparent
  • A leading axis of length 0 displays no printed lines

Operation application

  • Operations use programmed, stored, and/or computed result values
  • Only the Is (Gets)--local or global--copies a value to storage
  • No basic operation specifies output
  • A final computed value, not ending as stored, will be printed
  • "Foreign" verb connects to system devices and values, other programs
  • Each verb has default ranks of application: monadic, left, right
  • A Rank adverb may be applied to any value to direct its use
  • A Rank adverb may be applied to any verb to change from its defaults
  • A rank-n array is a frame of rank n-2 holding rank-2 arrays
  • An operation on rank-2 subarrays composes results in the same frame
  • With two arguments, one frame must match a prefix of the other
  • Values in the smaller frame will repeat to fill the larger
  • Smaller partial results will be filled to shape of largest
  • Performing operation within box values obviates fill at that level
  • Arithmetic operations use rank 0, applying to individual atoms
  • Specifying another rank applies elements of one over subarrays
  • Count and Shape Of use infinite rank (_), measuring a whole array
  • Rotate uses ranks 0 1; multiple left values give multiple rotations
  • A rank 1 (or _1) operation on a table treats whole rows together
  • A whole-row operation may, in turn, process individual atoms
  • +/table yields sums of rows: row+row+...+row (sums "down columns")
  • +/"1 table yields sums "along" rows: (atom+...+atom),...,(atom+...)
  • Some verbs apply rank-1 structural arguments to successive axes

Program structure

  • The Right verb (]) can isolate an expression yet deliver its value
  • The Left verb ([) can hide the result of a trailing expression
  • Either Identity (] or [) can follow storage to prompt printing
  • A verb-valued expression may contain monadic and dyadic definitions
  • Longer programs may be introduced by the Explicit verb (:)
  • The right argument may be a quoted expression, or 0 for keyed input
  • Successive lines become statements in the stored program
  • Control phrases (if., for., while., etc.) may punctuate the program
  • An if-test value is True unless it has a leading atom of unboxed 0
  • A separate single closing parenthesis terminates the definition
  • Arguments to a defined verb initialize local variables x, y
  • Values assigned locally (=.) are not visible anywhere else
  • A break. can terminate iteration before the stated end condition
  • A return. can terminate verb execution before its physical end
  • The last non-control expression evaluated becomes the verb's result

Tacit definition--not using local variables

  • Non-data expressions may define verbs, adverbs, conjunctions
  • A defined verb may combine its arguments via other verbs, modifiers
  • The first-acting verb applies to the argument(s)
  • Later verbs may apply to the result, if indicated by Atop or At
  • The full right argument of Atop/At usually needs parenthesization
  • Aside from a nest of Atops, the most common form is a chain of forks
  • Last and third-last verbs act on argument(s), middle on their results
  • A verb may be Right or Left to select either argument
  • A verb may introduce an additional value, via Bond
  • A value Bonded to Left yields itself--when left argument is absent
  • A value Bonded to Left Atop Right always yields itself
  • Fork arguments are not delivered to phrases Atop fork main verbs
  • x f@g y is equivalent to f (x g y) or x f@([ g ]) y
  • Some nests of Atops can be strung out as successive forks
  • A verb in a fork may itself be a fork, usually parenthesized
  • The left verb of a fork may be Cap to force the middle one monadic
  • Omitting Cap leaves a hook, which delivers arguments differently

Contributed by Art Anger