Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uunet.ca!geac!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: Array I/O in J.
Message-ID: <1992Feb1.054042.5696@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
References: <1992Jan30.035425.2938@newstand.syr.edu>
Date: Sat, 1 Feb 92 05:40:42 GMT

In article <1992Jan30.035425.2938@newstand.syr.edu> bli@lynx.cat.syr.edu (Bin Li) writes:
 
> One problem still not clear to me is how to perform the conversions
> between numerical data and character data in J. For example, I use
>
>    (, ,"1&(10{a.) ":array) 1!:2 < 'file_name'
>
> to output a 2 dimensional  array.  Then I do this
>
>    infile =. (".;._2) 1!:1 <'file_name'
>
> to read it back in.  They look the same but the internal representation of
> "infile" is neither integer nor floating point number.  How can I convert
> it back to the numerical representation so that mathematical operations
> can be performed on array "infile"?
 
The verb 3!:1 (internal representation) and its inverse 3!:2, when composed 
with 1!:1 (read) and 1!:2 (write), do as you ask for numeric and literal 
arrays.  Thus:
 
   ir    =. 3!:1
   ri    =. 3!:2
   read  =. 1!:1
   write =. 1!:2
   atf   =. ir@[ write ]
   aff   =. ri@read
 
   a =. o.i.3 4       NB. A table of pi's
   a atf <'asdf'      NB. write array a to file 'asdf'
   aff <'asdf'        NB. read an array from file 'asdf'
   3+aff <'asdf'      NB. as above, but add 3 to it

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