💾 Archived View for blitter.com › apl-books › apl.maxhost.org › openapl-notes.txt captured on 2022-07-16 at 17:21:35.
View Raw
More Information
-=-=-=-=-=-=-
openAPL employs 1-origin indexing
this help file uses UTF-8 encoding with the KAPL font
but openAPL uses ISO-8859-1 encoding
when editing these notes be sure to:
export LC_ALL=en_US.UTF-8
apl executes apl script and sets fonts and
keymappings necessary for openapl
under KDE 3.5.10 the compose key is set to right windows key
this invokes:
setxkbmap -option keypad:oss,compose:rwin
which is necessary to get the keyboard to work for openapl
issuing a xmodmap command like 'xmodmap usapl.txt' will
mess up the keymap necessary for openapl to work. One must
exercise care when working with other versions of apl.
if apl is executed from another shell such as konsole it
will be necessary to export LC_ALL=ISO-8859-1 to make sure
the keys work as expected
type locale at the bash prompt to be sure LC_ALL is set correctly
setup notes
-----------
openapl needs rxvt4apl and elvis to run
elvis needs /etc/elvis/elvis.ini to contain:
set! nonascii=all
.inputrc must also be patched
$if openapl
set editing-mode emacs
set convert-meta off
set input-meta on
set output-meta on
$endif
the file .aplrc must also be present in the $HOME directory
and be corrected configured
)clear clear out all functions and variables
)license displays software license
)lib list all files in current directory
)vars list all variables
)fns returns all functon names
)load test load workspace test
)save test save workspace test
)shell executes bash shell
)prws print contents of workspace in readable form
)code test display compiled internal code for function test
)edit test edit function test (text file)
)write test write function test
)erase test erase function test
)read test read function test
)list test list function test
)drop test deletes any file called test
)sic clear the state indictator
)trace turn on function trace
)untrace turn off function trace
)debug toggles debug mode on and off
)memory report on dynamic memory allocation
for following key sequences alt is right-alt
--------------------------------------------
alt shift s generates reversal ÷ along last axis
alt shift c generates comment ã
alt shift d generates reversal á along first axis
alt shift a generates transposition ô
alt shift h generates the ascending sort è
alt shift g generates the descending sort ç
alt shift o generates the natural log ð
alt shift b gives execute â
alt shift n gives format î
alt shift - gives matrix inverse ⌹
alt shift ' gives quotequad ì
alt \ gives diamond þ (different from aplus)
alt / gives reduce ¯ (first axis)
alt = gives multiply « (different from aplus)
alt - gives divide ß (different from aplus)
alt 2 generates high minus ¢
alt 4 generates less than or equal to ¤
alt 6 generates greater than or equal to ¦
alt 8 generates not equal ¨
alt 9 generates logical or © or monadic type
alt shift 9 generates logical nor ¹
alt 0 generates logical and ^
alt shift 0 generates logical nand °
alt shift 5 generates depth ½
alt [ gives û operator
alt shift [ gives ý operator
alt e gives member Å
alt g gives del Ç
alt shift g gives delstile ç
alt j gives jot Ê
alt i gives interval É
alt shift i gives ibeam à
alt s gives ceiling Ó
alt d gives floor Ä
alt l gives box Ì
alt r gives reshape Ò
alt u gives drop Õ
alt y gives take Ù
alt m gives magnitude Í
alt n gives encode Î
alt b gives decode Â
alt v gives dot Ö
for the following key sequences alt is left-alt
-----------------------------------------------
alt = similar to )lib but in alphabetical order
alt t transpose words
alt u change word under cursor to uppercase
shift 1 gives ! or factorial
shift 8 gives * or exponent
shift 9 gives (
shift 0 gives )
shift = gives +
shift , gives <
shift . gives >
control codes
-------------
ctrl-a beginning of line
ctrl-e end of line
ctrl-p fetch previous line
ctrl-n fetch next line
ctrl-c interrupt process
ctrl-d logs off
ctrl-u erases entire line
ctrl-w erases word
ctrl-i generates tab (or tab completion)
ctrl-l clears screen
tab generates tab
ctrl-j carriage return
ctrl-m carriage return
escape codes
------------
\b backspace
\n newline
\t horizontal tab
\nnn 8-bit chacter of octal value nnn
cursor keys do not work as expected
backspace does not work as expected (use ctrl backspace instead)
delete does not work as expected
note that cursor keys, delete and backspace now work as expected once readline is included
variables are case sensitive, e.g.
r and R represent two different variables
(É50)+50 returns the numbers 50 to 100
1 ^ 1 1 and 1 returns 1
?3 returns a random number from 1 to 3
?5 5 5 5 5 returns five random numbers from 1 to 5
!5 returns factorial of 5 which is 120
!.5 note that fractional or generalized factorials
are possible, this returns 0.88622692
«/ ((É3) + 4)
returns rising factorial of 5, e.g. 5«6«7)
3!5 returns the binomial (!B) divided by (!A) times !(B-A)
which is 10 in this example (i.e. choose 3 from 5)
2!3 choose 2 from 3, which occurs in 3 ways
2 ! 2 3 4 5
choose 2 from 2, 3, 4 and 5, returns 1 3 6 10
1.3 ! 8.9 fractional binomials are also possible,
this example returns 14.3692786
Ï1 returns pi or 3.14159265
- 1 returns euler's constant or 2.71828183
ð2 returns natural log of 2 or 0.693147181
«1 returns signum, ¢1 for negative, 0 for zero and 1 for positive
m û 3 3 Ò É9
returns 1 2 3
4 5 6
7 8 9
«/Ò m returns the number of elements of m
m[2;2] returns 5
+/[1]m add up all the columns (reduce last axis)
+/[2]m add up all the rows (reduce first axis)
+¯m add up all the rows, i.e. 6 15 24 (rows are the first axis)
m < 0 returns which elements are less than zero
m û 'gerbie power'
3 ÷ m returns bie powerger (rotates 3 characters to the left)
a û 3 « n û 2
an example of multi-assignment, a becomes 6 and n becomes 2
a û 1 + b û 3
another example of multi-assignment, a becomes 4 and b is 3
2 3 Ò 'abcdef'
returns abc
def
4 Ò '*' returns ****
12 Ò v û 1 2 3
stores 1 2 3 1 2 3 1 2 3 1 2 3 in v
'abcd' É 'b'
returns the index of b in abcd, i.e. 2
'abcd' É 'e'
if there is no match then 5 is returned
8 9 7 É 5 9 6 8
returns 4 2 4 1
2 * 2.5 fractional exponents are allowed, returns 5.65685425
a û 'apple'
b û 'pear'
c û a,b stores applepear in c
1 0 1 0 1 /'abcde'
returns ace
1 1 1 1 1 / 4
returns 4 4 4 4 4
0 1 1 0 1 / 1 2 3 4 5
compress (left arguments must be 1 or 0)
returns 2 3 5
u û 1 0 1 0
u / 'abcd' returns ac
0 1 0 / 3 3 Ò É9
returns 2
5
8
u û 1 0 1 0 1
u \ 6 3 2 returns an expansion or 6 0 3 0 2
v û 1 0 0 1
v \ 2 2 Ò É4
returns 1 0 0 2
3 0 0 4
a û 6 7 8 9 10
a[É3] returns the first 3 elements of a, i.e. 6 7 8
' ' ¨ 'this is it'
returns 1 1 1 1 0 1 1 0 1 1
'it''s' returns it's
'hello the number is'; 45
returns hello the number is 45
'abc' = 'abd'
returns 1 1 0
cû'3 4'
+/âc returns character 7
c û 'abcdef'
3Ùc returns abc
v û 1 2 3 4 5
v > 4 returns 0 0 0 0 1
v[1 2 5] returns 1 2 5
Ó/v returns largest element of v, i.e. 5
-v returns ¢1 ¢2 ¢3 ¢4 ¢5 (negates v)
+/v returns the sum of all the elements of v, i.e. 15
+/v > 3 returns 2 (number of elements greater than 3)
-/v returns 3 (this is the alternating sum)
i.e 1+3+5-(2+4) = 3
vÉ3 returns index of 3 in v which is 3
b û 'power of the gerbil'
Ò b returns 19
(b = 'o') / ÉÒ b (returns positions of o)
returns 2 7
(b Å 'aeiouy') / ÉÒ b
returns 2 4 7 12 15 18 (returns positions of all vowels)
v û 1 2 3 4 5 6 7 8 9 10
v Ê.« v
returns ten times table
tt û v Ê.« v
+/ ,tt sum all the elements of the ten times table
(here the monadic operator , unravels the two dimensional
array so we can sum all it's elements)
nÊ.+n û 1 2 3 4
combining assignment with outer product
10Ê.ßÉ5 returns 10 divided by 1 through 5
1 2 3 4 +.= 1 3 3 5
counts matches in corresponding positions, i.e. 2
1 2 3 4 +.> 2 1 4 5
counts values on left which are greater than right, i.e. 1
table û 3 4 Ò É12
table ^.= 5 6 7 8
returns which rows match, i.e. 0 1 0
(É3) Ê.= É3
returns identity matrix
8 8 8 Â 1 2 3
convert octal number 123 to decimal (returns 83)
8 8 8 Î 83 convert decimal number 83 to octal (returns 1 2 3)
x û 5
'the value of x is ',îx
returns the value of x is 5
v û 1 2 3 4 5
10 2 î v example of formating numbers with decimal points
returns 1.00 2.00 3.00 4.00 5.00
a û 4 5 6
a [3 2 1] û a
reorders a
tab û Ìav[10]
assign tab character to variable
k û 16 16 Ò 32Õ Ìav
store all printable characters as a 16x16 matrix in k
v û 1 2 2 3 3 3 4 4 4 4
u û ((vÉv)=ÉÒv)/v
u is assigned unique elements of v
m û 3 4 Ò É12
m[2; ] returns 5 6 7 8 or 2nd row
m[;3] returns all rows, column 3 i.e. 3 7 11
ß/1 2 3 4 5
finds alternating product, i.e. 1«3«5ß(2«4) = 1.875
Ìûxû5*3 assign 5*3 to x and display x
xû 1 2 3
x[2]û 5 x is 1 5 3
cube û 6 3 3 Ò 0
initialize a 3 dimensional array
cube[1;;] û 1
set every element of the first 3x3 to 1
b û 1 2 3 4
c û 5 6 7 8
d û b,[.5]c
d is assigned combined arrays, i.e.
d is set to 1 2 3 4
5 6 7 8
a û 2 2 Ò É4
b û ⌹a b is assigned the matrix inverse of a
then a +.« b gives the identity matrix
x û 3 + Ì
prompts user to enter data with Ì: prompt, expression
is evaluated after user hits enter
v û 1 2 3 , Ì
assign array plus input to v
ý2 goto line 2 of a function
aû1 ; bû2 assign a the value of 1 and assign b the value of 2
(note that this is implementation specific, other apl
versions use þ as a separator)
Ìai account information, displays user id
Ìav atomic vector which displays all symbols
Ìcr 'test' display canonical representation of function test
Ìct displays the comparison tolerance
Ìio display origin
Ìioû1 set origin to 1
Ìlx latent expression executed on activation of workspace
Ìnc 'v' returns 2 (symbol is a label or variable)
Ìnl 2 returns all variables
Ìnl 3 returns all functions
Ìpp printing precision, number of digits of precision
Ìpw printing width, default is 72
Ìts time stamp, displays year, month, day, hour, minutes, seconds
and milliseconds
Ìchdir '..'
change to parent directory
Ìrun 'ps -efw'
run any unix command
ibeams
------
à1 toggles state of code trace flag
à2 toggles state of stack trace flag
à3 toggles state of memory trace flag
à4 toggles state of variable trace flag
5 à35 sleep for 5 seconds
workspaces
----------
userfunc.ws
ulam.ws
primer.ws workspace containing functions primer1 and isprime
functions
---------
boxit 1 7 Ò 'wowzers'
prints wowzers horizontally boxed by asterisks
fib 12 prints the first 12 numbers of the fibonacci series
+/ fib 12 sum the first 12 numbers of the fibonacci series
prime 100 prints prime numbers less than or equal to 100 (rather slow)
prime1 100 prints prime numbers less than or equal to 100
uses sieve of eratosthene (much faster than prime)
+/ prime1 100
sum all the primes less than or equal to 100
+/ (3 take prime1 100)
sum the first 3 primes
Ò prime1 100
number of primes less than or equal to 100
71 Å prime1 71
is 71 prime? returns 1
Combinations
------------
outer product Ê. combined with + - ß « = ¨ Ä Ó Í > ¦ ¤ !
inner product combines any two operators, e.g.
v û 1 2 3 4 5
v +.+ v returns 30
5 +.« 3 2 1
this is equivalent to dot product, normally the vectors
are the same length but having only one element seems ok
returns 30
1 2 3 +.«1 2 3
returns 14 (1 + 4 + 9)
file IO
-------
0 Ìopen 'test.txt'
open file test.txt for reading and returns file descriptor
Ìclose fd close file by referencing file descriptor
Ìrd fd read one line from file referenced by fd
Ìseek (fd, 0, 0)
seek to beginning of file referenced by fd
differences, missing or problematic
-----------------------------------
openapl does not support nested arrays or complex numbers
)wsid missing
)grps missing
)out missing
)help some versions of apl actually have help
)origin replaced by Ìio
)width replaced by Ìpw
'a b c' ~ ' '
does not work in openapl (works in aplx)
'abcd' Ê.¨ 'aefg'
does not work in openapl, Domain Error: not numeric data
this works in APL\360
typing Ì on a line by itself and entering test crashes openapl
Ìcr 'test' will crash if function test does not exist
)load prime will crash if prime is a function, use )read for functions
½ the depth operator is not supported
Ú the disclose operator is not supported
⌹2 in other apl versions the reciprocal is returned if
the right argument to matrix inverse is a number, but in
openapl this gives a rank error
nested variables are not supported
assignments such as:
product û +/
are not permitted
observations
------------
function names can be placed inside variables and executed
commands such as )vars can not be placed in variables and executed
between any two constants, variables, or quads (ignoring parentheses)
there must be one, and only one, dyadic function
openapl does not use italicized letters
)erase will erase functions or variables from a workspace,
e.g. )erase prime prime1 v will erase functions prime and prime1 and
variable v
note that 5 factorial which is normally written as 5! is typed !5 instead
this is true for all versions of APL