home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 March / SOFM_Mar1995.bin / mac / SRI / General Interest / Programming / J / Examples / init.js < prev    next >
Encoding:
Text File  |  1993-12-02  |  2.7 KB  |  100 lines  |  [TEXT/????]

  1.    NB. standard J initialization
  2.    NB.
  3.    NB. (excluding windows definitions)
  4.    
  5.    t=. 'TAB LF CR CRLF EAV PAV'
  6.    t=. t,' script sscript read write append out'
  7.    t=. t,' names erase drep tree lrep ts timer'
  8.    t=. t,' bind box datatype gets indx list nl'
  9.    t=. t,' toCR toLF toCRLF type'
  10.    SCRIPTNAMES=: t
  11.    
  12.    TAB   =: 9{a.
  13.    LF    =: 10{a.
  14.    CR    =: 13{a.
  15.    CRLF  =: 13 10{a.
  16.    EAV   =: 255{a.
  17.    PAV   =: 254{a.
  18.    
  19.    NB. box if open
  20.    NB. can be used with external conjunctions requiring boxed arguments,
  21.    NB. e.g. allowing both  read '\config.sys'  and  read <'\config.sys'
  22.    box=:       ]`<@.(32&>@(3!:0))
  23.    
  24.    script=:    0!:2&box f.
  25.    sscript=:   0!:3&box f.
  26.    read=:      1!:1&box f.
  27.    write=:     (1!:2 box) f.
  28.    append=:    (1!:3 box) f.
  29.    out=:       1!:2&2
  30.    names=:     4!:1
  31.    erase=:     4!:55&box f.
  32.    drep=:      5!:2&box f.
  33.    tree=:      5!:4&box f.
  34.    lrep=:      5!:5&box f.
  35.    ts=:        6!:0
  36.    timer=:     (1000&*)@(6!:2)     NB. result in milliseconds
  37.    
  38.    NB. bind   - bind monadic verb to an argument creating a new verb
  39.    NB.          that ignores its argument
  40.    NB.
  41.    NB. e.g.   fini=: out bind 'finished...'
  42.    bind=:  [. @ (]. (&[))
  43.    
  44.    NB. datatype    
  45.    t=. ;:'boolean literal integer floating complex boxed'
  46.    datatype=: {&t@(2&^.@(3!:0)) 
  47.    
  48.    NB.  gets        - get script
  49.    NB. 
  50.    NB.  syntax:  {directory} gets name
  51.    NB.       file extension is set to .js
  52.    NB.       directory defaults to 'examples\'
  53.    gets=: 0 : 0
  54. 'examples\' gets y.
  55. :
  56. SCRIPTNAMES=: i.0 0
  57. 0!:3 <x.,y.,'.js'
  58. SCRIPTNAMES
  59. )
  60.    
  61.    NB. indx
  62.    NB. used to build case statements (e.g. in Windows programs)
  63.    NB. syntax:  verb=. gerund indx noun
  64.    NB. resulting verb looks up noun in its argument, and executes
  65.    NB. corresponding item from gerund
  66.    indx=:  [. @. (]. (&e.) (i.&1@))
  67.    
  68.    NB. list
  69.    NB. syntax:   {width} list data
  70.    NB. accepts data as one of:
  71.    NB.   boxed list
  72.    NB.   character vector, delimited by CR, LF or CRLF; or by ' '
  73.    NB.   character matrix
  74.    NB. formats in given width, default 77
  75.    list=: 0 : 0
  76. 77 list y.
  77. :
  78. $.=. >(2=#$y=. >y.){$.;L0
  79. $.=. $. #~ 0<#y.
  80. d=. (' ',LF) {~ LF e. y=. toLF ": y.
  81. y=. [;._2 y, d #~ d ~: {: y
  82. L0) y=. y-. ' '{.~ c=.{:$ y=. (": y),.' '
  83. (- 1>. <. x. % c) ;\ <"1 y
  84. )
  85.    
  86.    NB. nl  - namelist, e.g. nl 3 lists verbs in workspace
  87.    nl=:    list@(4!:1)
  88.    
  89.    NB. toCR returns character strings delimited by CR, etc.
  90.    subs=.    [. & ((((e.&) (# i.@#@)) (@])) })
  91.    crlf=.    #~ -.@(CRLF&E.)
  92.    toLF=:    LF subs CR @ crlf f.
  93.    toCR=:    CR subs LF @ crlf f.
  94.    toCRLF=:  2&}.@;@(((CR&,)&.>)@<;.1@(LF&,)@toLF)
  95.    
  96.    NB. type    (of object)
  97.    t=. <;._1 '/not defined/NA/noun/verb/adverb/conjunction/other'
  98.    t=. {&t@(4!:0)
  99.    type=: t&box f.
  100.