[comp.lang.apl] basic data representation

news@usc.edu (09/11/90)

In article <429@kepler1.kepler.com> rjfrey@kepler.com (Robert J Frey) writes:

   >[...description of application deleted...] I would think that reading lists
   >of numbers from files  would be  such a basic need that others must have 
   >solved this  problem. Is there some neat way to do this?

   ...

   As far as doing it within APL itself, I can offer two suggestions:
   First, use 'ss' to make the substitutions, eg, '-' ->
   negative-sign, 'e+' to 'E', etc.  then do an 'execute foreach' on
   the nested character string. Second, ...

actually, it is not clear that any string substitutions need to be
made.  Simple character substitutions should be more than adequate for
this kind of thing.

For example, to change e to E, and + into 0, just adjust the ascii
values of each e.  In J, this might be expressed:
m =. a. {~ (a. i. m) + ((-/a. i. 'Ee') * m='e') + (-/a. i. '0+') * m='+'

Or, in a more standard apl, this would look something like:
M <- []AV[ ([]AV i M) + ((-/[]AV i 'Ee') x M='e') + (-/[]AV i '0+') x M='+']

This technique can easily be extended to convert commas to whitespace,
or whatever, minus sign into negative sign, or whatever.  You could
also consolidate the starting and ending characters into vectors, or
whatever, and encapsulate the logic in some nice little package--if
that pleases you.

There is also the matter of implementation limits.  Can you pull a
megabyte file into memory and convert it all at once, or must you loop
through it is smaller chunks?  But as I remember, the original
question was more about the details of the character representation.