💾 Archived View for blitter.com › apl-books › apl.maxhost.org › apl-11.txt captured on 2022-07-16 at 17:20:43.
-=-=-=-=-=-=-
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