[comp.lang.apl] Dyalog question

jph@suns.UMD.EDU (J. Patrick Harrington) (09/11/90)

Thanks  for the replies - I'm glad to see there are a few  Dyalog 
users  on the net,  and that I was not overlooking something much 
simpler.  I first tried the "each" operator,  which did work  for 
positive  numbers without exponents.  For the more general  case, 
I've  only  been  able to do the conversion  line  by  line.  The 
following function does what I need at present. Let the unix file 
'NAME'  have N rows with J numbers in each (assuming no more than 
10000 rows); then "UR" puts the numbers into the array Z of shape 
N by J:  

  Z <- UR NAME;R;N;J;I
[1]  'unixfiles'[]SH'unixfiles' 'open' 'tread' 'close'
[2]  'xutils'[]SH'xutils' 'ss'
[3]  R <- 2 tread (N <- open NAME) 10000 & close N
[4]  J <- 1 cel dc shape execute ss(ss(ss(dc R[1])'-' '@')'e' 'E')'+' ''
[5]  N <- dc shape R & Z <- N J reshape 0 & I <- 1
[6]  ONE: Z[I;] <- execute ss(ss(ss(I pick R)'-' '@')'e' 'E')'+' ''
[7]  ->(N ge I <- I+1)/ONE

  where   dc=disclose,   @=high  minus,   ge=greater  or   equal, 
&=diamond,  and cel=ceiling.  Line [5] looks at the first row  to 
find  the  number of columns in the file. 
   Still,  it  would be nice to have  something  "smarter",  that 
would  fill short rows with zeros,  discard non-numeric comments, 
etc.  
                                         J.P. Harrington
                                         jph@astro.umd.edu
  

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

In article <7273@umd5.umd.edu> jph@suns.UMD.EDU (J. Patrick
Harrington) writes:

   Thanks  for the replies - I'm glad to see there are a few  Dyalog 
   users  on the net,  and that I was not overlooking something much 
   simpler. ... 

     Z <- UR NAME;R;N;J;I
   [1]  'unixfiles'[]SH'unixfiles' 'open' 'tread' 'close'
   [2]  'xutils'[]SH'xutils' 'ss'
   [3]  R <- 2 tread (N <- open NAME) 10000 & close N
   [4]  J <- 1 cel dc shape execute ss(ss(ss(dc R[1])'-' '@')'e' 'E')'+' ''
   [5]  N <- dc shape R & Z <- N J reshape 0 & I <- 1
   [6]  ONE: Z[I;] <- execute ss(ss(ss(I pick R)'-' '@')'e' 'E')'+' ''
   [7]  ->(N ge I <- I+1)/ONE

     where   dc=disclose,   @=high  minus,   ge=greater  or   equal, 
   &=diamond,  and cel=ceiling.  Line [5] looks at the first row  to 
   find  the  number of columns in the file. 
      Still,  it  would be nice to have  something  "smarter",  that 
   would  fill short rows with zeros,  discard non-numeric comments, 
   etc.  

First off, I'm not a Dyalog user, so maybe I should just shut up...

However, normally, the way you 'fill short rows with zeros' is with an
overtake.  e.g. on line [6] 
                            ONE: Z[I;] <- J take execute ....

As for discarding non-numeric comments, well.. that depends on what a
comment is, but try:

[5.5]        B <-     J reshape 0
[6]   ONE:   T <-     ss(ss(ss(I pick R)'-' '@')'e' 'E')'+' ''
[6.1]     ->(~ v/  '0123456789'   element_of T)/NEXT
[6.2]     ->(~ ^/ T element_of '@0123456789E ')/NEXT
[6.3]        B[I ] <- 1
[6.4]        Z[I;] <- J take execute T
[7]   NEXT:  I <-     I + 1
[8]       ->(N ge I)/ONE
[9]          Z <-     B /[1] Z


note that element_of is the old familiar epsilon, and that
~ v/ may be done more quickly as ~ 1 element_of, and that
~ ^/ may be done more quickly as   0 element_of

'nuf said

adam@ste.dyn.bae.co.uk (Adam Curtin) (09/12/90)

In article <7273@umd5.umd.edu> jph@suns.UMD.EDU (J. Patrick Harrington) writes:
>Thanks  for the replies - I'm glad to see there are a few  Dyalog 
>users  on the net,  and that I was not overlooking something much 
>simpler.

I'm glad, too - I worked for Dyadic until January, and unixfiles and xutils
are about 90% my code (the rest being due to Martin Tann).

Your problem may have a different solution with Dyalog APL version 6, which
replaces unixfiles with nfiles (all mine!), which has very sophisticated
input and output translation - using the apltrans and aplkeys tables. It's
easy to define a pair of translation tables which will do the translations from
ASCII numeric text to APL numeric text for input, and the reverse translation
on output. Then all you need to do is ravel, execute and reshape!

In the absence of nfiles, and not wanting to put you off using my program (!),
don't neglect monadic []SH. The right argument can be any shell command line,
whose output is captured (if the result is assigned) to a vector of vectors,
one element per line of output. This opens up the use of tr, sed, awk,
pipelines of uniq, sort, pr, ... the sky's the limit.

Adam

PS As a thinly-disguised sales pitch, Dyalog APL version 6 also has 'jade'
(just another development environment) with windowy editing, execution trace
and variable watching (jade due to yours truly and John Scholes). Version 6 is
the first version of Dyalog APL to be available for DOS (on 386 or better).

PPS Dyadic are now at Riverside View, Basing Road, Old Basing, Basingstoke,
Hampshire RG24 0AL, UK.
Tel: +44 256 811125; Fax: +44 256 811130.
-- 
A. D. Curtin			  .	Tel  : +44 438 753430
British Aerospace (Dynamics) Ltd. .	Email: adam@ste.dyn.bae.co.uk
PB 230, PO Box 19, Six Hills Way, . <This disclaimer conforms to RFC 1188>
Stevenage, SG1 2DA, UK.		  .	"My other car is an FJ1200"

rjfrey@kepler.com (Robert J Frey) (09/13/90)

In article <1990Sep12.094140.107@ste.dyn.bae.co.uk> adam@ste.dyn.bae.co.uk (Adam Curtin) writes:
>
>I worked for Dyadic until January, and unixfiles and xutils
>are about 90% my code (the rest being due to Martin Tann).
>

A great piece of work!

>
>In the absence of nfiles, and not wanting to put you off using my program (!),
>don't neglect monadic []SH. The right argument can be any shell command line,
>whose output is captured (if the result is assigned) to a vector of vectors,
>one element per line of output. This opens up the use of tr, sed, awk,
>pipelines of uniq, sort, pr, ... the sky's the limit.
>

This is a great environment to work in. We often prototype in APL, but are
easily able to integrate normal UNIX tools via monadic quadSH. We
then identify code we want to implement as AP's and prototype them as 
shell scripts or "quick-and-dirty" programs, integrated with monadic quadSH
and/or ASCII files written and read with unixfiles and xutils. Finally, the 
required code is implemented as standard AP's and we use dyadic quadSH so 
they appear in the APL workspace itself as functions.

Obviously, in the early stages of this process we make extensive use of monadic
quadSH and the unixfiles and xutils AP's. This iterative refinement of imple-
mentation details allows us to focus on basic design issues early on and helps
us get a working system up and running very quickly and continue to improve it
steadily as time goes on.

On the research side, because so much code is experimental or run-once-then-
throw-away, having a method for linking existing tools into APL with a trivial
amount of work is important. Also, many of our researchers are hired for their
mathematical, not programming skills, and quadSH, unixfiles and xutils are
easier to use than AP's (though not as efficient).

>
>Dyadic are now at Riverside View, Basing Road, Old Basing, Basingstoke,
>Hampshire RG24 0AL, UK.
>Tel: +44 256 811125; Fax: +44 256 811130.
>
-- 
Dr. Robert J Frey, Kepler Financial Management, Ltd.
rjfrey@kepler.com *or* frey@chaos.sunysb.edu
voice: (516) 689-6300 * fax: (516) 751-8678