💾 Archived View for blitter.com › apl-books › apl.maxhost.org › aplus-notes.txt captured on 2024-05-12 at 16:35:23.
⬅️ Previous capture (2022-07-16)
-=-=-=-=-=-=-
this file uses UTF-8 encoding A+ employs 0-origin indexing and the index origin is always 0 when using firefox to view text pages about aplus use KAPL font with UTF-8 encoding when editing this file aplus-notes.txt use kedit with KAPL font and UTF-8 encoding use kedit to edit aplus scripts but use LC_ALL=ISO-8859-1 examples of aplus in this file can be clipboarded and run in aplus when using aplus: xmodmap usapl.txt necessary to get the alt key to work as expected export LANG=en_GB.iso8859 this may be necessary for scripts export LC_ALL=ISO-8859-1 this may be necessary for scripts system variable names begin with `. examples in ~/Downloads/aplus-fsf-4.22/src/a environment variables are $ATREE and $APATH keys specific to aplus ---------------------- alt shift c generates the comment character, everything on that line is a comment alt shift 4 generates the sort symbol è alt shift 5 gives circle with vertical line ÷ alt shift 6 gives transpose ô alt shift f gives depth ½ alt shift 8 gives natural log ð alt shift b gives execute â alt shift a gives á alt shift n gives format î alt 1 generates each ¡ alt 2 generates high minus ¢ alt 3 generates enclose < alt 7 generates greater than > alt 8 generates not equal ¨ alt 9 generates logical or © or monadic type alt 0 generates logical and ^ alt [ gives û operator alt ] gives ý operator (clears error, $ also clears error) alt - gives multiply « alt = gives divide ß alt shift = gives matrix divide alt / gives ¯ alt s gives ceiling Ó alt d gives floor Ä alt u gives drop Õ alt y gives take Ù alt n gives encode Î alt b gives decode  alt i gives interval É alt e gives member Å alt ` gives diamond þ alt ' gives left Ý alt ; gives right Û alt v gives separate symbols Ö alt q gives ? alt l gives box Ì alt o gives pi times Ï alt r gives reshape Ò alt z gives partition/partition count Ú alt x gives pick/raze Ø $load s loads screen management facilities $load disp load display function $load loop.+ load an apl program and execute it $load prime.a load user function prime into workspace operating system commands in general can be accessed by preceeding the $ symbol before it: $date $time in other versions of APL the box symbol is used for built-in variables, but in aplus $ is used instead: $pp returns the number of digits of precision which is 10 $cd /home/cubeman change directory to home directory $clear clears screen $mode returns current mode (e.g. apl or ascii or uni) $off logs out of aplus $vars returns all the variables $sfs returns system function names $fns returns all functon names $si state indicator $vers returns version of aplus $reset reset all suspensions $mode ascii set ascii mode $ops list operators $cmds list all commands $globs list all global objects $cxs display a list of all the context names $cx c switch to context c $cx . return to root context $Gf 1 sets protected mode on É10 returns the numbers 0 to 9 «/(É10)+1 returns 10 factorial +\É5 returns 0 1 3 6 10 (É50)+50 returns the numbers 50 to 99 | ¢5 returns absolute value, e.g. 5 3 3 Ò É9 returns the numbers 0 to 8 in a 3x3 matrix v û 3 3 Ò É9 +/ v sum the columns +/@1 v sum the rows a û 'gerbie power' #a returns the number of characters or 12 Trail û 'Going to the trail' variable names are case sensitive ô2 6Ò 'Hello World!' returns Hello World! vertically a û 'apple' b û 'pear' c û a,b stores applepear in c 2ð1 2 4 8 16 32 returns log of 2, i.e. 0 1 2 3 4 5 +/2|3 4 5 6 7 returns the number of odd integers, i.e. 3 «\5Ò2 returns 2 4 8 16 32 +\+\5Ò1 returns 1 3 6 10 15 ÷(É5)+1 returns 5 4 3 2 1 ?3 returns a random number from 0 to 2 100 ? 100 generates 100 random numbers from 0 to 99 12/4 generate 12 4's 4 / 'abc' generates aaaabbbbcccc table û 3 3 Ò 1 2 3 4 5 6 7 8 9 table[2;2] returns 9 Ò table returns 3 3 c.b <- 'abcdef' store abcdef in b in the context of c %`a display a in the root context %`c.b display b in the c context xûÉ3 5 6 create 3 dimension array x x[0;0;0]û50 set the element at coordinates (0,0,0) to 50 aûÉ3 4 create 3x4 array with elements 0 to 11 a[]û5 set all elements of array to 5 ,a returns a unravelled into a straight line vector a û 1 2 3 a[,] û 4 append 4 to array a Òa returns 4 ÒÒÉ4 5 returns 2 (number of dimensions) 5ß(Õ2) the drop symbol Õ prints the expression following it this line returns 2.5 2 1 2 3 Ê.+ 4 5 6 outer product of + + Í 4 5 6 ---Í--------- 1 Í 5 6 7 2 Í 6 7 8 3 Í 7 8 9 1 2 3 Ê.« 4 5 6 outer product of « x û 'gerbil' xÊ.=x use outer product of = to compare every character of x to every other character 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 v û 1 2 3 4 5 v[0 1 4] returns 1 2 5 +/v returns sum across v +\v returns running sum across v wû1 2 ¢4 12 0 ¢7 14 2 ¢3 +/(w>0)«w returns sum of the positive numbers in w (w>0)+.«w shorter method doing the same thing xû1 1 1 0 1 1 0 1 +/^\x returns index of the first zero, i.e. 3 v û 3 3 5 6 7 8 1 9 3 4 5 7 7 ((vÉv)=É#v)/v returns only unique values of v, i.e. 3 5 6 7 8 1 9 4 nû10 xûn do Õn returns numbers 0 to 9 xû(nû10) do Õn same thing on one line z û 0 n û 10 n do zûz,n+1 returns 0 to 10 ' ' ¨ 'this is it' returns 1 1 1 1 0 1 1 0 1 1 aû1 bû0 a © b returns 1 (or) a ^ b returns 0 (and) 4« `arctan Ï1 returns pi Ï1 returns pi times 1 `sin Ï1 returns 0.8414709848 1Ï1 returns 0.8414709848 (same as above) `cos Ï1 returns 0.5403023059 (a; b; c) û 1 2 3 strand or multi-assignment a is 1, b is 2 and c is 3 (a; b; c) û 1 a b and c are all set to 1 a, b, c returns 1 2 3 aû1; bû2; cû3; multiple statements on one line are separated by ; v û 1 2 3 4 5 ÷v returns reverse order of v m û 'gerbie power' 3 ÷ m returns bie powerger (rotates 3 characters to the left) a û 1 2 3 1 ÷ a returns 2 3 1 ¢5Õ 'test12345' returns test (drops last 5 characters) 5Õ 'test12345' returns 2345 (drops first 5 characters) 'abc'Ý2 3 returns abc a[èa] Ý aû'barforoni' returns abfinoorr (characters are sorted) a û 14 56 34 11 0 ¢2 1 a[èa] returns ¢2 0 1 11 14 34 56 (numbers are sorted) ÷a[èa] returns 56 34 14 11 1 0 ¢2 (numbers are sorted in reverse order) a[ça] same as above 'cat' Å 'hat' returns 0 1 1 2 0 # 3 3Ò'abcdefghi' returns ghi (returns row 2 and row 0) abc 24 60 60Â1 7 0 returns 4020 convert 1 hour and 7 minutes to seconds 10 10 10  1 1 1 returns 111 8 8 8  1 2 3 convert octal number 123 to decimal (returns 83) 2 2 2  1 0 0 convert binary number 100 to decimal (returns 4) 1 < 2 returns 1 (true) 1 > 2 returns 0 (false) mean x: (+/x)ß#x mean 1 2 3 4 5 6 7 8 9 10 returns 5.5 f{}:'abc' f{} returns abc drop5 string : ¢5Õ string this is a function, e.g. drop5 'pumpkin' returns pu 3ÙÉ10 takes the first 3 items of É10 ¢3ÙÉ10 takes the last 3 items of É10 a û É¡ 3 4 5 a contains vectors É3, É4, and É5 s û'this is a test' bûs=' ' b returns 0 0 0 0 1 0 0 1 0 1 0 0 0 0 (Ú1,b)Ús returns separate words in s ôÉ3 3 transpose x and y elements aû1.42 1|a returns factional part of a â 'v û 1 2 3 4 5' execute a string 1 + â '1' convert character '1' to a number and add 1 b ý '2' a û â b convert character array b to int and store in a aû10 bû17 a+É1+b-a returns 10 11 12 13 14 15 16 17 © 'abc' returns `char which is the type © < 'abc' returns `box © _argv returns `box © `abc returns `sym © () returns `null b û 'twinkie' c û ' ' d û 'power' e û Ø (b; c; d) e becomes twinkie power <'abc' enclose a string, returns < abc ><'abc' discloses an enclosed string which returns the string ½<'abc' returns depth of enclosed string, e.g. 1 `int©3.4 4.5 5.6 cast float as integer, returns 3 5 6 `char©97 returns ascii character 97 a û 1 b û î a store a as text in b © b returns `char v û '$vars' âv commands can be placed in variables and executed 2Ò¡ 3 4 5 < 3 3 < 4 4 < 5 5 w û É¡1 2 3 4 < 0 < 0 1 < 0 1 2 < 0 1 2 3 2Ò< 'cat' < cat < cat 4!'fourbeartops' restructure string into 3 strings of 4 characters ¢3!v restructure v into 3 parts a û (1 2 ; 'abc' ) create nested array and store in a vû 53 14 27 2 31 85 30 11 67 50 gû`v show `g is `graph display graph of g `g has (`title;"Graph Tutorial Example") give graph a title show v displays vector v in a window t û 'test' show t as `text displays text in a window $load disp disp.lay (10 32;'abc') disp.lay 2 2 Ò É4 a û 1 2 3 4 5 disp.int (a) sets up a display of an integer array b û 'the power of gerbie' disp.char (b) sets up a display of a string disp.enbox (b) sets up a string with a simple box disp.disp (x) displays any type of array or function disp.disp (a;b;c) display arrays a b and c m û 1.234 disp.float (m) sets up a display of a floating point array $fns disp list functions in context disp $fns s list functions in context s $load box $fns box list functions in context box box.in $load t t.tile show tile function t.calendar show calendar function '$load dio' beforehand t.calendar ('01/01/2013 ý 01/02/2013') argument is a character vector in the form of mm/dd/yyyy function returns an integer vector: 20130101 20130102 20130103 t.intersect {v ; w } v and w can have integer or character data curly braces must be used show elements common to v and w t.unique {'apple'} returns aple t.file_exists {'/home/cubeman/text/wine.txt'} returns 1 dio.parse ('12/12/2013') 20131212 ¢999999999 if(`int=©4294967296) wordsizeû64 else wordsizeû32; returns wordsize $load s s.CDE returns 1 if running the CDE window manager, otherwise return 0 s.reset{} free all objects (has the effect of closing all windows) mûsys.readmat{'prime.a'} read text file into character variable m sys.sleep{10} sleep for 10 seconds sys.filesize{'yum.txt'} returns size of file yum.txt sys.gethostname{} returns name of current host machine sys.readenv {"HOME"} returns /home/cubeman sys.username {0} sys.getpid{} returns pid of a+ sys.system('cd $HOME') sys.system executes system calls sys.system('sh') drop to bash shell returns username corresponding to the user id, e.g. root 'g<99:99:99>' _fmt 100Â3Ù3Õsys.ts{} returns time in 24 hour format _gsr{'apple is';'is'; 'is not';''} global search and replace, 'is' is replaced with 'is not' _load 'disp' loads script file and reports full pathname _nl{`disp; `vars} named list, lists variables in context disp _nl{`;`cxs} list all contexts _nl{`;`apl} list all keywords and symbols for APL mode _nl{;Ï} list all circle functions multi-line functions -------------------- total m: {