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
Joy (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!
== Overview == Functions in Joy lack [[Parameter (computer science)|formal parameters]]. For example, a function that squares a numeric input can be expressed as follows:<ref>{{cite web|title=An informal tutorial on Joy |url=http://www.latrobe.edu.au/phimvt/joy/j01tut.html |url-status=dead |archive-url=https://web.archive.org/web/20111007030359/http://www.latrobe.edu.au/phimvt/joy/j01tut.html |archive-date=October 7, 2011 }}</ref> DEFINE square == dup * . In Joy, everything is a function that takes a [[stack (data structure)|stack]] as an argument and returns a stack as a result. For instance, the numeral '5' does not represent an integer constant, but instead a short program that pushes the number 5 onto the stack. * The '''dup''' operator simply duplicates the top element of the stack by pushing a copy of it. * The '''*''' operator pops two numbers off the stack and pushes their product. So the square function makes a copy of the top element, and then multiplies the two top elements of the stack, leaving the square of the original top element at the top of the stack, with no need for a formal parameter. This makes Joy concise, as illustrated by this definition of [[quicksort]]:<ref>{{cite web|title=Sequence Library |url=http://www.latrobe.edu.au/phimvt/joy/seqlib.joy |url-status=dead |archive-url=https://web.archive.org/web/20111007030359/http://www.latrobe.edu.au/phimvt/joy/seqlib.joy |archive-date=October 7, 2011 }}</ref> <pre><nowiki> DEFINE qsort == [small] [] [uncons [>] split] [swapd cons concat] binrec. </nowiki></pre>
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)