home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / JS.ZIP;1 / DBASE.JS < prev    next >
Encoding:
Text File  |  1992-12-31  |  3.0 KB  |  148 lines

  1.    NB.  This file can be used as a script input file to J Version 6.1
  2.    NB.  December 1992
  3.    
  4.    NB.  Donald B. McIntyre
  5.    NB.  Luachmhor, 1 Church Road
  6.    NB.  KINFAUNS, PERTH PH2 7LD
  7.    NB.  SCOTLAND - U.K.
  8.    NB.  Telephone:  In the UK:      0738-86-726
  9.    NB.  From USA and Canada:   011-1-738-86-726
  10.    NB.  email:  donald.mcintyre@almac.co.uk
  11.    
  12.    NB. Using J's Boxed Arrays
  13.    NB. VECTOR  Vol. 9#1 (July 1992) 92-105
  14.  
  15.    NB. Basic Techniques Relating to Boxes.
  16.  
  17.    ]a=. i.2 3
  18.    $a
  19.    ]b=. <i.2 3
  20.    $b
  21.    ]c=. 'mary';'jones';a; 1 3 5
  22.    $c
  23.    3 1 2 0{c
  24.    ;:s=. 'here we go gathering nuts in may'
  25.    #&.> ;: s
  26.    mean=. +/%#          NB.  Fork
  27.    mean > #&.> ;: s
  28.    mwl=. mean @ (>@(#&.> @ ;:))
  29.    mwl s
  30.    $> ;:s
  31.    > ;:s
  32.    /:~ > ;: s
  33.    sort=. /:~@(>@;:) NB. This is not a Hook.  Parentheses required
  34.    sort s
  35.    v=. 2 3.4 5.67
  36.    <"0 v
  37.    $,. v
  38.    ,. v
  39.    ]m=. i.2 3 4
  40.    <"2 m
  41.    <"1 m
  42.  
  43. NB. Construct a Simple Database
  44.  
  45.    d=.,:'E.E.';'McDonnell';'Palo Alto';27;10000; 8 3 12 25 10
  46.    d=.d,'Ken';'Iverson';'Toronto';55;15000; 4 19 32 1 15 10
  47.    d=.d,'Donald';'McIntyre';'U.K.';61;12000;''
  48.    d=.d,'Roger';'Hui';'Toronto';49;20000; 32 4
  49.    d=.d,'Anthony';'Camacho';'U.K.';45;35000; 19 23 45 4 17 13 5
  50.    d
  51.  
  52.    col=. >@{"1
  53.    locality=. 2&col
  54.    locality d
  55.  
  56.    name=. 1 [ age=. 3 [ salary=. 4
  57.  
  58.    sort=. ] /: col          NB.   Fork
  59.  
  60.    ]n=. name sort d
  61.    ]s=. salary sort d
  62.  
  63.    name=. 1&col
  64.    n-: (/: name) d          NB.   Hook
  65.    s-: (/: 4&col) d         NB.   Hook
  66.  
  67.    mean=. +/%#
  68.    mean age col d
  69.    mean salary col d
  70.  
  71.    each=. &.>
  72.    meanr=. mean each @ (5&{"1)
  73.    meanr d
  74.    sortr=. ] /: > @ meanr          NB.  Fork
  75.    ]z=. sortr d,"1 0 meanr d
  76.  
  77.    sortr=. /: > @ meanr            NB.  Hook
  78.    z-: sortr d,"1 0 meanr d
  79.  
  80.    d #~ >(<'Toronto') -: each 2{"1  d
  81.    place=. '' : 'd #~ > (< x.) -: each 2{"1 y.'
  82.    place=. ] #~ > @ (<@[ -: each 2&{"1@])
  83.    place
  84.    'U.K.' place d
  85.  
  86. NB. Replacement and Insertion
  87.  
  88.     ir=. ($@[ #. ])"2 1
  89.     x=. 9 8 7 6,:5 4 3 2
  90.     (<x) (d ir 2 5)} d
  91.  
  92.     i=. 2 5,:4 2
  93.     (x;'London') (d ir i)} d
  94.   
  95. NB. Expansion in General, and a Digression on Reading J
  96.  
  97.    exp=. /:@\:@[{#@[{.]
  98.    1 0 1 exp 7 8
  99.    exp=. /: @ \: @ [ { # @ [ {. ]
  100.    exp=. /:@\:@[ { #@[ {. ]
  101.  
  102.    p=. /:@\:@[
  103.    q=. {
  104.    r=. #@[
  105.    s=. {.
  106.    t=. ]
  107.    1 0 1 (p q r s t) 7 8
  108.    f=. p q r s t
  109.    f
  110.    tree=. 5!:4 @ <
  111.    tree 'f'
  112.  
  113.    exp
  114.    tree 'exp'
  115.  
  116. NB. Adding New Items to the Database
  117.  
  118.    ] e=. 1 0 1 1 0 1 1 exp d
  119.  
  120.    f=. 1&{@$
  121.    g=. i.@f@[
  122.    h=. f@[ * ]
  123.    p=. g + h
  124.    q=. p f.
  125.    q
  126.    row=. q"2 0
  127.    e row 4
  128.    e row 1 4
  129.  
  130.    x=. 'Bob';'Bernecky';'Toronto';35;22000; 4 5
  131.    ]e=. x (e row 1)} e
  132.  
  133.    x=.'Graham';'Woyka';'U.K.';62;35000; 14 31 5 7
  134.    ]e=. x (e row 4)} e
  135.  
  136. x=.('Graham';'Woyka';'U.K.';1;2;3),:'Vin';'Grannell';'Los Angeles';4;5;6 7 8
  137.    
  138.    e=. 1 0 1 1 0 1 1 exp d
  139.    x (e row 1 4) } e
  140.  
  141.    ]z=. (1 0{x) (e row 1 4)} e
  142.    z-: e (e row 1 4)}~ 1 0{x
  143.  
  144.    ]y=. 1 0{x
  145.    i=. e row 1 4
  146.    z-: y i} e
  147.    z-: e i}~ 1 0{x
  148.