[net.lang.apl] What APL2 Really Has

6006118@pucc.BITNET (David Laur) (05/23/86)

 
Frank Adams remarked:
 
>
>One advantage of a proper implementation of variable declarations is that
>one would be able to define a function as operating on, say, two scalar
>arguments; if invoked with two arrays of the same dimensions, it would
>automatically be called for each corresponding pair of scalars.
>
 
I thought for sure that there would be a fast response from someone at
IBM research on this one ... they've been using APL2 (in various guises)
for YEARS now!  Our site, Princeton University, has had it online for
about 3 years and we have some people who use it heavily.  We do not
have any I.P. Sharp systems, so I can't say much about their
enhancements; and I don't know very much about the STSC APL/UNX product
except that they seem to have decided to use IBM's APL2 as the model
for their general array extensions.  I would like to set the record
straight on a few items which people seem to be confused about.
 
First of all, I don't know the religious vocabulary which should be
used when discussing variable declarations, but I will try to explain
the APL model from my point of view.  I think that many people would
argue that one of the things that makes APL easy to use is that the
user does NOT have to worry about declaring variables!  More importantly
though, the APL approach has been to allow 'any' kind of data in arrays
(variables) and then to allow the functions to decide (selectively) if
their arguments are from a useable domain or class of objects.  Again,
in APL the important distinctions are between numeric and character
types, and distinguishing between the shapes and ranks of arrays.
My interpretation of the comment about APL needing variable declarations
was that there is a need to describe the structure of the array rather
than 'type' of the elements.  The specific example application given
is a perfect introduction to the new powers of APL2.  One of the most
important things to have come out of the development of APL2 is the
formalization of many 'loosely defined' APL concepts.  Among them, the
concepts of 'a scalar' and of 'scalar functions'.  For some primitive
functions in APL, the two arguments are somewhat independent of each
other; for example, the left argument to RESHAPE is a description of the
new shape for the array right argument, these two arguments are usually
very different in their shape and size.  Other primitives, like PLUS,
require that their arguments be identical in rank and shape; they return
a result of the same size which is produced by operating on
corresponding elements in the arguments in a pairwise fashion.
Functions which work, pairwise, on the scalar elements of the argument
arrays are called 'scalar functions'.  User defined functions in VS/APL
and APL2 can not be defined to be scalar functions, which would solve
the stated problem; however, in APL2 there is a new operator (recall the
distinction between functions and operators in APL) which will turn any
function into a scalar function.  It is called EACH and it will work on
both primitive and user defined functions, for example:
 
    this expression:   2 3 4 reshape each 10 20 30
           produces:   10 10  20 20 20  30 30 30 30
          (which is a 3 element, nested vector of vectors)
 
The symbol for EACH is the dieresis -- the shift-one character which
looks a little like a sideways colon.  It can also be used with monadic
functions:
 
    this expression:   iota each 1 2 3
           produces:   1  1 2  1 2 3
          (which is also a 3 element, nested vector of vectors)
 
Since this operator can be used with user defined functions, it will
easily solve the problem posted previously without introducing
variable declarations or 'structure' definitions.
 
So, what else does APL2 have, (you ask, knees quivering) ...
 
_________________________________
 
A partial list of enhancements (over IBM VS/APL):
 
   - General Arrays
        . that is: arrays whose scalar elements are other arrays,
          these arrays can have ANY shape, rank, and mixture of types
        . primitive which makes arrays into scalars (Enclose)
        . primitive which undoes Enclose (Disclose)
        . primitive for determining depth of nesting (Depth)
        . primitive for reaching any level of a nested array (Pick)
        . primitive which does a 'super ravel' on nested arrays (Enlist)
        . Strand Notation for explicitly typing nested arrays
          note: this is a 'natural' extension of   A <- 1 2 3
          there isn't an explicit 'glue' function between the numbers.
 
   - Complex Numbers  (Yep)
        . Can be used anywhere
        . Primitives like '*' changed to produce complex results
        . New circle functions
        . Real and Imaginary format - 1.4J3
        . Magnitude and Angle format
               Degrees - 25.3D90
               Radians - 25.3R1.5707
 
   - The Each operator, as described above
 
   - There are now user defined Operators as well as functions
 
   - User defined functions and operators can be used anywhere that
     primitive ones can, eg:  jot.MYFCN  or  MYFCN/VECTOR
 
   - Also operator expressions are allowed: +.*/Vector_of_Matrices
 
   - Nested Assignment:   (A B C) <- 1 2 3
     this would assign 1 to A, 2 to B, and 3 to C
 
   - Selective Specification, this is an extension of A[2;3] <- 17
     the new feature allows any selection expression in assignment,
     for example: ((VECTOR='x')/VECTOR) <- 'y'
 
   - A primitive for finding occurrences of one string in another (Find)
 
   - A primitive called 'without' for set-type operations: A without B
 
   - You can use Xedit as the APL editor
 
   - You can use lower case letters instead of underscored letters
 
   - There is support for 2*31 characters
 
   - There are supplied functions which call special assembler code for
        . Finding the roots of polynomials (answers can be complex)
        . Finding Eigenvectors and Eigenvalues
 
   - You can enter commands and get error messages in any of
     12 national languages.
 
   - There is a )HOST command for talking to the underlying system
 
   - There is a new aux processor for SQL/DS and DB2
 
   - There is a new aux processor for ISPF
 
   - APL2 users can share variables with each other
 
   - There are many new tools for error trapping and analysis
 
   - The symbol table grows and shrinks dynamically
 
   - Character data is now in standard system format (ebcdic)
 
   - There is a very clever new interface via a new system function
     called quad-NA:
        . It is essentially a way to call compiled programs from APL2
        . There is custom tailored support for programs written in
                FORTRAN
                Assembly Language
                Rexx  (a very nice PL/1ish exec language under CMS)
        . the interface will actually support anything which uses
          the OS calling conventions, so many programs written in
          C, COBOL, Pascal, etc can also be used.
        . As a result there is now direct access to existing subroutine
          libraries, such as IMSL.
 
        . There are some 'example' tools supplied with the interface
          which are very useful additions to APL:
                Fast File i/o
                Parsing functions, eg: strings -> vector of words
                An interface to GDDM's subroutine library
 
 
   - And many more ...
_________________________________
 
I'd be happy to be more specific if anyone is curious, and I would
certainly like to hear about the features/pitfalls of other enhanced
versions of APL.  Perhaps this would be a good opportunity for me to
'fan my own flame' (pardon) and informally announce that Princeton
and IBM will be jointly sponsoring an APL2 short course for
experienced APL programmers on 14-16 July 1986; topics and speakers
will be posted formally soon, but the course will be an introduction
to the new features just mentioned and some discussion of how to
use them effectively.
                             David M. Laur
Strike while the iron is.    Bitnet: 6006118@PUCC
                             UUCP: allegra!psuvax1!pucc.BITNET!6006118