this document refers to the version of apl\11 that comes with 2.11BSD may 1982 version ---------------- this version can be compiled and is a separate executable the stripped executable is 66466 bytes uncompress apl.tar.Z in /usr/src/new/PORT/ tar -xvf apl.tar files are in ~/apl11-files ai.c was updated to use vi apl\11 employs 1-origin indexing only use lower case for variable names 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 -m use apl terminal 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 clears workspace )erase list erase functions or variables )fuzz 10 set fuzz to 10 )lib list all workspace names )load mark1 load workspace mark1 )save mark1 save workspace mark1 )edit test edit function test (this also puts function test in memory) )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 (I usually use 120) )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 (the function must be present in current workspace) )script file everything typed in the apl environment is written to file Lrun 'ls' runs commands such as ls Lcr 'say' display canonical representation of 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 (some call this the multiplicative inverse) 2 % 1 2 3 4 5 returns 2 divided by 1 through 5 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 e.g +\ 1 2 3 4 returns (1) (1+2) (1+2+3) (1+2+3+4) or 1 3 6 10 X/ v product all elements of v X\ v returns running product across v S/v returns largest element of v D/v returns smallest element of 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 (also known as binomial coefficient) 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 -(1 + 2) negation of 1 + 2 which is -3 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 +a { 1 2 3 assign 1 2 3 to a and display 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 a E 1 returns 1 0 0 0 0 0 0 0 0 a { 2 2 R 4 7 2 6 sets a as 4 7 2 6 1O1 returns sin at 1 2O1 returns cos at 1 a { 7; b { 8; c { 9 multiple statements on one line 3 E 1 2 3 returns 1 4 E 1 2 3 returns 0 'cat' E 'hat' returns 0 1 1 24 60 60 B 1 7 0 returns 4020 (total seconds in one hour and 7 minutes) 24 60 60 B 24 0 0 returns 86400 (total seconds in 24 hours) 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 ? 6 6 simulate a dice roll 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) also possible are J.= J.> J.< J.- J.X J.* J.% J.& J.^ J.$ J.# a +.* b returns 260 inner product of exponentiation e.g. (1*3) + (2*4) + (3*5) = 260 a { 3 `2 b { `1 7 a +.X b returns the inner product of a and b which is -17 3(-1) + (-2)7 = -3 + -14 = -17 this is also referred to as the dot product of a and b example of matrix multiplication: (number of columns of first matrix must be equal to number of rows of second matrix) a { 2 3 R I6 b { 3 2 R I6 a +.X b returns 22 28 49 64 *1 returns the base of natural logarithm (e) e.g. 2.71828183 v { I10 v J.X v returns ten times table (multiply) +/ , v J.X v sum the ten times table a { 1 2 3 4 5 b { 3 4 5 6 7 c { (aEb)/a c is assigned the intersection of the elements in both a and b -/ 1 2 3 becomes 3 - (2 - 1) or 2 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 b { L^H% a a +.X b returns the identity matrix, e.g. 1 0 0 1 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) quotequad inputs data has a string x { 3 'x is ',N^HJ x displays x is 3 'x is '; x displays x is 3 c { 'catbat' 'b' E c is b an element of c, returns 1 v { 2 2 R I4 L^H% v returns -2.0 1.0 1.5 -.5 B^HJ 'v { 1 2 3' executes string v { I5 10 2 N^HJ v example of formating numbers with decimal points 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 assign _ for assign } for goto $ for less than or equal to & for greater than or equal to ` for negative sign ~ for not % for reciprocal # for not equal ^ for and , for catenate or ravel | for mod or absolute value / for reduce (compress) /^H- for reduce first axis \ for expand V for or C for comment R for rho E for epsilon I for iota 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 sign or multiply X for sign or multiply % for divide L for quad (for numeric input) overstrikes ----------- apl\11 uses overstrikes in the form of op1 ^H op2 N^HJ for format B^HJ for execute L^H% for matrix divide or matrix inverse <^H= for less than or equal to O^H| for reverse \^HO for transpose 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. While editing a function use ^V^H (ctrl-V then ctrl-H) so that vi will add a hex 08 byte. using plain ed works too :) L^H% 2 in other apl versions the reciprocal is returned if the right argument to matrix inverse is a number, but in the 2.11BSD version this gives an mdom conformability error functions --------- fact 10 lists factorial of number prime 50 lists prime numbers up to 50 prime1 50 lists prime numbers up to 50, faster than prime primen 1000 lists prime numbers up to 1000, faster than prime1 primei 100 lists the first 100 primes fib1 produce fibonacci series, e.g. 10 fib1 0 1 blank lines within a function are OK e.g. f { x rising y C compute the rising factorial C e.g. 5 rising 3 gives 5 X 6 X 7 f { X/ ((Iy) + (x-1)) scripting --------- apl-old -m mark123 < prime-100 load workspace mark123 and execute instructions in file prime-100 and exit