Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
APL (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== ''Pick 6'' lottery numbers ==== This following immediate-mode expression generates a typical set of ''Pick 6'' [[lottery]] numbers: six [[pseudo-random]] [[integer]]s ranging from 1 to 40, ''guaranteed non-repeating'', and displays them sorted in ascending order: <syntaxhighlight lang="apl"> x[βxβ6?40] </syntaxhighlight> The above does a lot, concisely, although it may seem complex to a new [[wiktionary:APLer|APLer]]. It combines the following APL ''functions'' (also called ''primitives''<ref>{{cite web|last1=MicroAPL|title=APL Primitives |url=http://www.microapl.co.uk/apl_help/ch_020_020.htm |website=www.microapl.co.uk |publisher=MicroAPL |access-date=January 11, 2015}}</ref> and ''glyphs''<ref>{{cite web |title=APL Font β Extra APL Glyphs |website=wiki.nars2000.org |url=http://wiki.nars2000.org/index.php/APL_Font |publisher=NARS2000 |access-date=January 11, 2015}}</ref>): * The first to be executed (APL executes from rightmost to leftmost) is dyadic function <code>?</code> (named <code>deal</code> when dyadic) that returns a [[array data structure|vector]] consisting of a select number (left argument: 6 in this case) of random integers ranging from 1 to a specified maximum (right argument: 40 in this case), which, if said maximum β₯ vector length, is guaranteed to be non-repeating; thus, generate/create 6 random integers ranging from 1 to 40.<ref>{{cite web |last1=Fox |first1=Ralph L. |title=Systematically Random Numbers |publisher=SIGAPL |url=http://www.sigapl.org/article1.php |website=www.sigapl.org |access-date=January 11, 2015}}</ref> * This vector is then ''assigned'' (<code>β</code>) to the variable <code>x</code>, because it is needed later. * This vector is then ''sorted'' in ascending order by a monadic <code>β</code> function, which has as its right argument everything to the right of it up to the next unbalanced ''close-bracket'' or close-parenthesis. The result of <code>β</code> is the indices that will put its argument into ascending order. * Then the output of <code>β</code> is used to index the variable <code>x</code>, which we saved earlier for this purpose, thereby selecting its items in ''ascending'' sequence. Since there is no function to the left of the left-most x to tell APL what to do with the result, it simply outputs it to the display (on a single line, separated by spaces) without needing any explicit instruction to do that. <code>?</code> also has a monadic equivalent called <code>roll</code>, which simply returns one random integer between 1 and its sole operand [to the right of it], inclusive. Thus, a [[role-playing game]] program might use the expression <code>?20</code> to roll a twenty-sided die.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
APL (programming language)
(section)
Add topic