Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!sun-barr!ames!haven.umd.edu!uunet!utcsri!geac!jtsv16!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: J verb for reading a file into J
Message-ID: <1992Oct16.043658.26746@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
References: <1992Oct11.064814.13447@csus.edu> <Bw159F.730@math.uwaterloo.ca> <1992Oct14.070249.11308@csus.edu> <1992Oct15.175017.16833@yrloc.ipsa.reuter.COM>
Date: Fri, 16 Oct 92 04:36:58 GMT
Lines: 39

The questions on "cut" remind me of a puzzle solved several years ago in
SAX (Sharp APL UNIX) which admits to a similarly simple solution in J:
On UNIX systems, the file /etc/passwd contains lines having 7 parts each,
separated by colons.  (As with other UNIX files, the lines are terminated
by the ASCII 10 character.)  The problem is to derive a matrix from
/etc/passwd with each part individually boxed.
 
As previously stated, f;._2 applies f to each suffix-delimited cut (each
line), excluding the delimiter.  Each line has parts separated by colons,
so if a colon is first appended, then <;._2 would box each part.  The puzzle 
can be solved thus:
 
   ] t=.1!:1 <'/etc/passwd'
tbj:x:119:335:Toronto Blue Jays:/usr/tbj:
abrave:x:120:334:Atlanta Braves:/usr/abr:
oath:x:121:334:Oakland Athletics:/usr/oa:/bin/csh
pp:x:122:335:Pittsburgh Pirates:/usr2/pp:/bin/csh
 
   g=.<;._2@(,&':');._2
   g t
+------+-+---+---+------------------+--------+--------+
|tbj   |x|119|335|Toronto Blue Jays |/usr/tbj|        |
+------+-+---+---+------------------+--------+--------+
|abrave|x|120|334|Atlanta Braves    |/usr/abr|        |
+------+-+---+---+------------------+--------+--------+
|oath  |x|121|334|Oakland Athletics |/usr/oa |/bin/csh|
+------+-+---+---+------------------+--------+--------+
|pp    |x|122|335|Pittsburgh Pirates|/usr2/pp|/bin/csh|
+------+-+---+---+------------------+--------+--------+
   $x=.f t
4 7
   4{"1 x
+-----------------+--------------+-----------------+------------------+
|Toronto Blue Jays|Atlanta Braves|Oakland Athletics|Pittsburgh Pirates|
+-----------------+--------------+-----------------+------------------+

------------------------------------
Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
Phone: (416) 925 6096;  Fax: (416) 488 7559
