home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 March / SOFM_Mar1995.bin / mac / SRI / General Interest / Programming / J / xenos.doc < prev   
Encoding:
Text File  |  1993-11-21  |  12.2 KB  |  407 lines  |  [TEXT/????]

  1. Copyright (c) 1989 1990, Roger K.W. Hui & K.E. Iverson
  2. Copyright (c) 1990-1993, Iverson Software Inc.
  3. All Rights Reserved.
  4.  
  5.  
  6. Roger Hui
  7. 1992 10 8
  8.  
  9.  
  10. The !: Conjunction:
  11.  
  12. The !: conjunction currently takes integer scalar left and right
  13. arguments, and derives verbs.  (One exception:  5!:0 is an adverb.)
  14. These verbs behave like other verbs; in particular, they have intrinsic
  15. ranks, may be assigned names, and may serve as arguments to adverbs and
  16. conjunctions.  Where these verbs take names as arguments (file names,
  17. WS names, or object names), the names are always boxed, and the verb
  18. rank is 0.
  19.  
  20. As with all other verbs, verbs derived from !: requires one or two
  21. arguments.  Some verbs have no "natural" arguments, but an argument
  22. must nevertheless be supplied (and will be ignored in execution).
  23. For example,
  24.      6!:0 ''
  25.   1991 6 6 10 50 23
  26.  
  27. NYA means not yet available.
  28.  
  29.  
  30. 0!:0      Host System Command
  31.   The string argument is forwarded to the host system for
  32.   execution, and the result is returned as a string with
  33.   embedded new-lines.  For example: 0!:0 'dir *.exe'
  34.  
  35. 0!:1      Spawn
  36.   0!:1 forwards its string argument to the host system for execution,
  37.   like 0!:0, but the output (if any) is ignored.  For example, 0!:1 can
  38.   be used to invoke the vi editor on UNIX systems.
  39.  
  40. 0!:2     Script
  41.  
  42. 0!:3     Silent Script
  43.   Script and Silent Script accept a boxed input file name as right
  44.   argument and an optional boxed output file name as left argument.
  45.   A boxed empty string right argument means "standard input", i.e.
  46.   the keyboard.  The input file consists of lines of J sentences and
  47.   other input lines, and is known as a "script".  The output file is
  48.   suitable for subsequent use as a script.  Script differs from Silent
  49.   Script in that it outputs to the "standard output" (the screen) as
  50.   well as to any output file.  Examples:
  51.  
  52.   (<'sesslog') 0!:2 <''
  53.     Input obtained from the keyboard; output appended to file
  54.     "sesslog" and to the screen.
  55.  
  56.   0!:3 <'\jscripts\asdf'
  57.     Input from file "\jscripts\asdf"; no output.  Input reverts
  58.     to the keyboard at the end of "\jscripts\asdf".
  59.  
  60.   (<'outf') 0!:3 <'disk:folder:subfolder:inf'
  61.     Input obtained from "disk:folder:subfolder:inf"; output
  62.     appended to "outf".
  63.  
  64.   0!:2 <''
  65.     Default.
  66.  
  67.   If there is a file named "profile.js" in the current directory,
  68.   J will automatically execute 0!:2<'profile.js' at the start
  69.   of a session.
  70.  
  71. 0!:4      Lines
  72.  
  73. 0!:5      Silent Lines
  74.   Lines and Silent Lines are like Script and Silent Script, but the right
  75.   argument is a string of lines separated by new-lines.
  76.  
  77. 0!:55     Terminate Session
  78.   0!:55 derives a verb which, when executed, terminates the session.
  79.  
  80. 1!:0      Directory  NYA
  81.  
  82. 1!:1      File Read
  83.   The argument is a boxed file name; the result is a string
  84.   of the file contents.  For example, 1!:1 <'dir\subdir\file.ext'
  85.   The file name follows the conventions of the host system.
  86.   The argument may also be the integer 1, meaning read from
  87.   the keyboard.
  88.  
  89. 1!:2      File Write
  90.   xyz 1!:2 <':folder1:folder2:file'  writes string xyz to the
  91.   specified file.  The right argument may also be the integer 2,
  92.   meaning write to the screen.
  93.  
  94. 1!:3      File Append
  95.   string 1!:3 <'disk:folder1:folder2:file'
  96.  
  97. 1!:4      File Size
  98.   1!:4 'dir/file1';'file2';'phile3'
  99.  
  100. 1!:11     Indexed File Read
  101.   The argument is a 2-element list of boxes: a file name and
  102.   a 2-element integer list of the index and length.  For example,
  103.   1!:11 'test';5 20  reads 20 bytes from file "test", starting
  104.   from position 5.  The index may be negative (the last byte of
  105.   the file is index _1).  The length may be elided, whence the
  106.   file is read from the index to the end of the file.
  107.  
  108. 1!:12     Indexed File Write
  109.   The right argument is a 2-element list of boxes: a file name
  110.   and an integer index.  For example,  xyz 1!:12 'test';14
  111.   writes (string) xyz to file "test", starting at position 14.
  112.   The index may be negative (the last byte of the file is index _1).
  113.   The positions to be written must already exist in the file (and the
  114.   file must already exist).
  115.  
  116. 1!:55     File Erase
  117.   1!:55 <'careful'
  118.  
  119. 3!:0      Internal Type
  120.   The internal "type" of a noun, where
  121.   1  boolean
  122.   2  literal
  123.   4  integer
  124.   8  floating point
  125.   16 complex
  126.   32 boxed
  127.   64 box with key
  128.  
  129. 3!:1      Convert to   Internal Representation
  130.   A string of the internal representation of a noun.  The result
  131.   is machine-dependent and may differ in different J versions.
  132.  
  133. 3!:2      Convert from Internal Representation
  134.   Inverse of 3!:1, but only nouns of type 2^i.5 are created.
  135.  
  136. 4!:0      Name Class
  137.   The argument is a boxed name; the result is its class:
  138.   _1 other
  139.   0  undefined, but valid name
  140.   1  (not used)
  141.   2  noun
  142.   3  verb
  143.   4  adverb
  144.   5  conjunction
  145.  
  146. 4!:1      Name List
  147.   The argument is integers from 2 to 5 (see 4!:0) or 6 for locales.
  148.   The result is a list of boxed names belonging to the class(es)
  149.   specified in the argument.  The optional left argument are initial
  150.   letters of the names of interest.
  151.  
  152. 4!:55     Erase
  153.   The object named in the boxed argument is erased.
  154.  
  155. 4!:56     Erase given name
  156.  
  157. 5!:0      Fix
  158.   5!:0 is an adverb which defines an object from its atomic or string
  159.   representations.  For example,
  160.  
  161.      fx =. 5!:0
  162.      ar =. 5!:1
  163.      ((ar <'a') fx) -: a =. i. 3 4
  164.   1
  165.      plus =. +
  166.      $$ ar <'plus'
  167.   0
  168.      2 ((ar <'plus') fx) 4 5
  169.   6 7
  170.  
  171.   If the argument is a boxed list of boxes, it is assumed to be
  172.   an atomic representation (a result of 5!:1).
  173.  
  174.   If the argument is a string, it is assumed to be a catenation
  175.   of string representations (results of 5!:3).  The objects are
  176.   defined, names embedded in the representation are assigned
  177.   as a side effect, and the result of 5!:0 is the last
  178.   represented object.
  179.  
  180. 5!:1      Atomic Representation
  181.   The argument is a boxed name; the result is a boxed list of
  182.   two boxes uniquely representing the named object:
  183.  
  184.   noun:         id  value
  185.   verb:         id  operator arguments
  186.   adverb:       id  operator arguments
  187.   conjunction:  id  operator arguments
  188.  
  189.   If an object is uniquely identified by the id alone (for example
  190.   "a." or "+" or "/."), then the second field is elided, and the
  191.   atomic representation is the id alone.
  192.  
  193.   Gerunds (results of the ` conjunction) are arrays of atomic
  194.   representations.  5!:0 defines an object from its atomic
  195.   representation.  Atomic representations are sometimes called
  196.   "canonical" or "boxed" representations.
  197.  
  198. 5!:2      Display Representation
  199.   The argument is a boxed name; the result is the display representation
  200.   of the named object.  5!:0 defines an object from its display
  201.   representation.  (Different objects can have the same display
  202.   representation, so 5!:0 is only a partial inverse.)
  203.      f =. +/ . *
  204.      f
  205.   +-----+-+-+
  206.   |+-+-+|.|*|
  207.   ||+|/|| | |
  208.   |+-+-+| | |
  209.   +-----+-+-+
  210.      each =. &. >
  211.      (5!:2 <'f') -: (, each '+/') ; each '.*'
  212.   1
  213.  
  214. 5!:3      String Representation
  215.   The argument is a boxed name; the result is a string of the WSIS
  216.   (Workspace Interchange Standard) representation of the named object.
  217.   5!:0 defines an object from its string representation.  See Section
  218.   5.3 of "An Implementation of J" for details.
  219.  
  220. 5!:4      Tree Representation
  221.   The argument is a boxed name; the result is a literal table of the
  222.   tree representation of the named object.  Box drawing characters
  223.   (9!:6 and 9!:7) are used to draw the connecting lines in a tree.
  224.   For example,
  225.      nub =. (i.@# = i.~) # ]
  226.      5!:4 <'nub'
  227.                +- i.
  228.          +- @ -+- #
  229.     +----+- =
  230.     |    +- ~ --- i.
  231.   --+- #
  232.     +- ]
  233.  
  234. 5!:5      Linear Representation
  235.   The argument is a boxed name; the result is a string which,
  236.   when interpreted, produces the named object.  For example,
  237.      nub =. (i.@# = i.~) # ]
  238.      5!:5 <'nub'
  239.   (i.@# = i.~) # ]
  240.      $5!:5 <'nub'
  241.   16
  242.      a=.o.i.3 4
  243.      5!:5 <'a'
  244.   3.14159265358979323*i.3 4
  245.  
  246. 6!:0      Time-Stamp
  247.   The current time as a 6-element list: year, month, day, hour,
  248.   minute, and second (including any fraction thereof).
  249.  
  250. 6!:1      Time since session start
  251.  
  252. 6!:2      Time required
  253.   The string right argument is executed the number of times specified
  254.   by the left argument (default: 1).  The execution results are discarded.
  255.   The result of 6!:2 is the average number of seconds required for the
  256.   execution.  For example:
  257.      time=.6!:2
  258.      time '+/i.10000'         NB. time to execute once
  259.      10 time '+/i.10000'      NB. time to execute, averaged over 10 times
  260.  
  261. 6!:3      Delay
  262.   (6!:3) 60 [ 'sleep for a minute'
  263.  
  264. 7!:0      Space currently in use
  265.  
  266. 7!:1      Space used since session start
  267.  
  268. 7!:2      Space required to execute an expression
  269.  
  270. 8!:0      (PC only) Query CGA mode
  271.   (8!:0 ''){'non-CGA mode'; 'CGA mode'
  272.  
  273. 8!:1      (PC only) Set   CGA mode
  274.   (8!:1) 0 [ 'set non-CGA mode'
  275.   (8!:1) 1 [ 'set CGA mode'
  276.  
  277. 8!:4      (PC only) Query screen attributes
  278.  
  279. 8!:5      (PC only) Set   screen attributes
  280.   The argument is a 4 by 2 matrix of integer values from 0 to 15.
  281.   Attribute values are interpreted as follows:
  282.   .---------------------------.
  283.   | input area  | input area  |
  284.   | background  | foreground  |
  285.   |-------------+-------------|  0  black     4  red
  286.   | output area | output area |  1  blue      5  magenta
  287.   | background  | foreground  |  2  green     6  yellow
  288.   |-------------+-------------|  3  cyan      7  white
  289.   | cursor bar  | cursor bar  |
  290.   | background  | foreground  |  8+i values in background specify "flashing";
  291.   |-------------+-------------|  in foreground, "bright".
  292.   | status line | status line |
  293.   | background  | foreground  |
  294.   |_____________|_____________|
  295.  
  296. 8!:7      (PC only) Refresh screen
  297.   Redisplay the contents of the screen.
  298.  
  299. 8!:9      (PC only) Edit
  300.   8!:9 y invokes the editor on y, a string with lines delimited
  301.   by linefeeds (10{a.). Press F1 to get meanings of function keys.
  302.  
  303. 8!:16     (Macintosh only) Query font attributes
  304.  
  305. 8!:17     (Macintosh only) Set   font attributes
  306.   Font attributes are a 3-element integer list of the font number,
  307.   style, and size.  "Style" is the sum of one or more of the following
  308.   integers, where
  309.     1  Bold
  310.     2  Italic
  311.     4  Underline
  312.     8  Outline
  313.   Font attributes can also be set by the font dialog box, invoked
  314.   by the "Font ..." item under the "Edit" menu.
  315.  
  316. 8!:19     (Macintosh only) Print screen
  317.  
  318. 9!:0      Query random link
  319.  
  320. 9!:1      Set   random link.  Default: 16807
  321.  
  322. 9!:2      Query display representation
  323.  
  324. 9!:3      Set   display representation
  325.   The argument is an integer vector of one or more representations
  326.   to be used for default output of verbs, adverbs, and conjunctions.
  327.     1  atomic (gerundial)
  328.     2  display
  329.     3  string
  330.     4  tree
  331.     5  linear
  332.  
  333.   For example:
  334.      nub =. (i.@# = i.~) # ]
  335.      nub
  336.   +-------------------+-+-+
  337.   |+--------+-+------+|#|]|
  338.   ||+--+-+-+|=|+--+-+|| | |
  339.   |||i.|@|#|| ||i.|~||| | |
  340.   ||+--+-+-+| |+--+-+|| | |
  341.   |+--------+-+------+| | |
  342.   +-------------------+-+-+
  343.      9!:3 (5 4)
  344.      nub
  345.   (i.@# = i.~) # ]
  346.               +- i.
  347.     +- @ -+- #
  348.     +---+- =
  349.     |   +- ~ --- i.
  350.   --+- #
  351.     +- ]
  352.  
  353. 9!:4      Query prompt
  354.  
  355. 9!:5      Set   prompt.  Default: '   '
  356.  
  357. 9!:6      Query box drawing characters
  358.  
  359. 9!:7      Set   box drawing characters
  360.   The argument is an 11-element string of  nw,ts,ne, te,cr,tw,
  361.   sw,tn,se, ns,ew  (northwest corner, tee south, northeast
  362.   corner; tee east, etc.)  Defaults:
  363.  
  364.   [PC    ]  218 194 191  195 197 180  192 193 217  179 196 { a.
  365.   [Others]  '+++++++++|-'
  366.  
  367. 9!:8      Query error messages
  368.  
  369. 9!:9      Set   error messages
  370.   For example: Replace English messages (default) with French ones.
  371.  
  372. 10!:k     Link to C function
  373.   For LinkJ, 10!:k invokes the function jc(k,f1,f2).  You must modify
  374.   jc() to assign values to f1 and f2 appropriate to k.  See Appendix C
  375.   of "An Implementation of J" for details.
  376.  
  377. 11!:0     (Windows only) Windows Driver
  378.   See on-line help (press F1).
  379.  
  380. 11!:1     (Windows only) Windows Visual Edit
  381.   The WP string argument is amended via a visual editor.
  382.  
  383. 12!:n     Reserved for trees
  384.  
  385. 13!:0     Reset stack (0 disables suspension, 1 enables)
  386.  
  387. 13!:1     Display stack
  388.  
  389. 13!:2     Stop query
  390.  
  391. 13!:3     Stop set
  392.  
  393. 13!:4     Run again
  394.  
  395. 13!:5     Run next
  396.  
  397. 13!:6     Exit and return value
  398.  
  399. 13!:7     Exit and cause result error
  400.  
  401. 128!:0    QR decomposition
  402.   The QR decomposition of a complex matrix in the domain of %. .
  403.   The result is an Hermitian matrix and a square upper triangular
  404.   matrix, individually boxed.
  405.  
  406. 128!:1    Invert a square upper triangular matrix
  407.