Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!uunet.ca!geac!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: J verb for reading a file into J
Message-ID: <1992Oct15.175017.16833@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
References: <1992Oct11.064814.13447@csus.edu> <Bw159F.730@math.uwaterloo.ca> <1992Oct14.070249.11308@csus.edu>
Date: Thu, 15 Oct 92 17:50:17 GMT
Lines: 47

Emmett McLean writes:
 
>    read_helper =. ' (<;.1)~ 1, (10 { a.) = y. ':11
>    read  =.' (; }:&.> read_helper y.) <;.1 (y. #~ (10 { a.) ~: y.) ':11
>
>    x =. 1!:1<'test'
>    x               NB. look at x
> 1 2 3
> 4 5 6
> 6 7 8
> 1 1 1
>    $ x             NB. x is presently a character matrix
> 24
>    $ > read x      NB. x as a character matrix
> 4 5
>    3 * ". > read x NB. numeric matrix times 3
>  3  6  9
> 12 15 18
> 18 21 24
>  3  3  3
 
Saying that "x is presently a character matrix" is misleading.  It is a
character list with embedded newlines which makes it look like a matrix.
The solution above is unnecessarily circumlocutory.  Since the system is
a VAX or NeXT, x consists of lines ending in ASCII 10.  Since the objects
are defined by a suffix and not a prefix, the 2 and _2 cuts are more
appropriate than the 1 or _1 cuts.
 
f;. 1   prefix delimited cuts; apply f to each cut including the delimiter
f;._1   prefix delimited cuts; apply f to each cut excluding the delimiter
f;. 2   suffix delimited cuts; apply f to each cut including the delimiter
f;._2   suffix delimited cuts; apply f to each cut excluding the delimiter
 
The following verbs may be useful:
 
f0=.< ;. 2       NB. Box each line, including nl.
f1=.< ;._2       NB. Box each line, excluding nl.
f2=.[ ;._2       NB. Convert lines into a character matrix, excluding nl.
f3=.".;._2       NB. Execute each line, excluding nl, resulting in a
							  numeric matrix.
 
Finally, the phrase   y.#~(10{a.)~:y.  for string y. can be simplified to
y.-.10{a.  .

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