Apparently-to: HOMER W. SMITH
Subject: APL SOLUTION NEEDED
From: donald.mcintyre@almac.co.uk (Donald Mcintyre)
Date: Fri, 18 Mar 94 17:11:00 +0000
Organization: ALMAC: Scotland : +44 (0)324 665371

Your problem: You have DOS data delimited by CRLF's (i.e. variable
length records). After reading this string you wish to pad and shape it
into a table where each row is the full length of the longest row with
all CRLF's removed. You don't allow any looping.

You don't say which version of APL you are using, but here is a session
executed with J Version 7. First create a test file:

   Cr=. 13{a. [ Lf=. 10{a.
   s=. 'Three', Cr,Lf,'blind mice',Cr,Lf,'see how they run',Cr,Lf
   write=. 1!:2 <
   s write 'test.fil'

Read the file:  (Note that $ gives the shape)

   read=. 1!:1@<
   $x=. read 'test.fil'
37

Only three operations are required: Drop the Line feeds; Cut into boxed
segments at the Carriage Returns; Open the result.  Define three
corresponding verbs and combine them:

   DropLf=. #~ ~:&Lf
   CutCr=. <;._2
   Open=. >
   f=. Open @ CutCr @ DropLf

   $y=. f x
3 16
   y
Three
blind mice
see how they run

This is the result you require. Here, however, are 4 alternative
formulations. The last two are particularly readable because, being
trains of 7 and 9 verbs respectively, they consist of forks and need no
parentheses.

   f=. >@(<;._2@(#~~:&Lf))
   f=. [: > [: <;._2 (#~ ~:&Lf)
   f=. [: > [: <;._2 [ #~ ~:&Lf
   f=. [: > [: <;._2 [ #~ ] ~: Lf"0

See also my paper "Using J with External Data" (Vector, vol.8#4, April
1992, p.97-110).

PS If you are unfamiliar with J and don't have a Dictionary handy, then
   of course you cannot expect to find what I have written "particularly
   readable". This, however, is nothing to do with any inherent
   difficulty it may have!

 * RM 1.2 01091 * donald.mcintyre@almac.co.uk
