Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
APL (programming language)
(section)
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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)