this document refers to the version of apl\11 that comes with 211bsd uncompress apl.tar.Z in /usr/src/new/PORT/apl tar -xvf apl.tar ai.c was updated to use vi apl\11 employs 1-origin indexing apl\11 was originally written by Ken Thompson and enhanced by Purdue University 211bsd.sh invokes 211bsd via simh man apl documentation on the apl interpreter apl invoke apl (probably better not to use -m option) apl < quick load quick note that any series of apl statements can be put in a text file, the apl executable processes all lines then exits )clear )load mark1 )save mark1 )off )digits 9 specifies that 9 digits are displayed )origin 1 set origin to 1 (other values are also possible) )width 80 set characters per line to 80 )vars list all variables )fns list all functions )drop mark1 delete mark1 )shell drops to bash shell )prws print contents of workspace in readable form )read say read function say (stored in ascii as file say) )list say list function say )script file everything typed in the apl environment is written to file Lrun 'ls' runs commands such as ls Lcr say execute function say Lnc 'x' determines what type of variable x is: 0 means variable is undefined 2 means variable is a label or variable 3 means variable is a function type 5*2 returns 25 5X3 returns 15 4%10 returns .4 (4 divided by 10) %2 returns the reciprocal of 2 5 10 15 X 2 multiply a series of numbers by 2 v { 1 2 3 4 5 +/ v sum all elements of v +\ v returns running sum across v X/ v product all elements of v X\ v returns running product across v !v returns factorial of all elements of v v[1,2] returns elements 1 and 2 O1 returns pi times 1 !5 returns factorial of 5 !3.5 returns 11.6317284 (fractional factorials are permitted) `5 returns negative 5 |`5 returns absolute value of negative 5 2*.5 returns square root of 2 2 ! 4 choose 2 from 4, i.e. 6 1 ^ 1 1 and 1 returns 1 1 V 0 1 or 0 returns 1 3 $ 4 3 is less than or equal to 4, returns 1 I5 returns interval 5, e.g. 1 2 3 4 5 'b' > 'a' returns 1 (true) 1 # 2 1 not equal 2 returns 1 ' ' = 'this is it' returns 0 0 0 0 1 0 0 1 0 0 v { 1 2 3 4 5 O^H| v reverses v v[1 2 3] returns first 3 elements of v v[] { 3 set all elements to 3 a { a,6 append 6 to a 5D7 returns 5 (min) 5S7 returns 7 (max) a { 3 3 R I9 ,a returns 1 2 3 4 5 6 7 8 9 1O1 returns sin at 1 2O1 returns cos at 1 a { 7; b { 8; c { 9 multiple statements on one line 'cat' E 'hat' returns 0 1 1 24 60 60 B 1 7 returns 4020 (total seconds in one hour and 7 minutes) 8 8 8 B 1 2 3 converts octal number 123 to decimal (83) a { 3 3 R I9 \^HO a transpose x and y elements of a 1 4 7 2 5 8 3 6 9 1.25e5 returns 125000 ?3 returns random number from 1 to 3 a { 1 2 3 b { 3 4 5 a J.* b returns outer product * (exponent) 1 1 1 8 16 32 27 81 243 a J.+ b returns outer product + (plus) note that J.= and J.> and J.< are also possible a +.* b returns 260 (inner product, not sure what this does) v { I10 v J.X v returns ten times table (multiply) +/ , v J.X v sum the ten times table v { I5 v J.- v returns all elements of v subtracted from all elements of v a { 2 2 R I4 L^H% a returns matrix inverse of a a { 3 5 0 7 8 12 1 a[ |^HH a ] returns 0 1 3 5 7 8 12 note that grade up must be typed as | ctrl-H H 1&1 1 is greater than or equal to 1, returns 1 0 Lopen 'manual' read file manual (returns file handle 4) Lrd 4 read one line from file handle 4 4 Lread 20 read 20 bytes from file handle 4 v { L^H' v is assigned with user input (L^H means quotequad) x { 3 'x is ',N^HJ x c { 'catbat' 'b' E c is b an element of c, returns 1 B^HJ 'v { 1 2 3' executes string B^HN 20 example of an ibeam, generally B ctrl-H N followed by a number in this case it returns the total number of 1/60 sec intervals since midnight B^HN 28 returns the date B^HN 29 returns the origin B^HN 32 returns number of workspace bytes in use replacement characters ---------------------- $ for less than or equal to & for greater than or equal to ` for negative sign ~ for not % for reciprocal # for not equal ^ for and V for or C for comment R for rho E for epsilon Y for take (up arrow) U for drop (down arrow) D for min (floor) S for max (ceiling) N for encode B for decode M for multiply L for quad (denotes start of a function) limitations ----------- no nested arrays I've recompiled apl to use vi as the editor but there's a problem with any operator of the form A ^H B in that you can't type that sequence into vi and expect apl to process it correctly. One must use the )script command and create any lines with these operators then read them into the appropriate part of the file. using plain ed works too :)