The Joy programming language in
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
is a
purely functional programming language
In computer science, purely functional programming usually designates a programming paradigm—a style of building the structure and elements of computer programs—that treats all computation as the evaluation of mathematical functions.
Program ...
that was produced by Manfred von Thun of
La Trobe University
La Trobe University is a public university, public research university based in Melbourne, Victoria (Australia), Victoria, Australia. Its main campus is located in the suburb of Bundoora, Victoria, Bundoora. The university was established in 196 ...
in
Melbourne
Melbourne ( ; Boonwurrung/ Woiwurrung: ''Narrm'' or ''Naarm'') is the capital and most populous city of the Australian state of Victoria, and the second-most populous city in both Australia and Oceania. Its name generally refers to a me ...
,
Australia. Joy is based on composition of functions rather than
lambda calculus
Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation t ...
. It has turned out to have many similarities to
Forth
Forth or FORTH may refer to:
Arts and entertainment
* ''forth'' magazine, an Internet magazine
* ''Forth'' (album), by The Verve, 2008
* ''Forth'', a 2011 album by Proto-Kaw
* Radio Forth, a group of independent local radio stations in Scotla ...
, due not to design but to an independent evolution and convergence. It was also inspired by the
function-level programming style of
John Backus
John Warner Backus (December 3, 1924 – March 17, 2007) was an American computer scientist. He directed the team that invented and implemented FORTRAN, the first widely used high-level programming language, and was the inventor of the Backu ...
's
FP.
How it works
Joy is unusual among functional programming languages (except for
function-level programming languages and some esoteric ones, such as
Unlambda) in its lack of a
lambda
Lambda (}, ''lám(b)da'') is the 11th letter of the Greek alphabet, representing the voiced alveolar lateral approximant . In the system of Greek numerals, lambda has a value of 30. Lambda is derived from the Phoenician Lamed . Lambda gave ris ...
operator, and therefore lack of
formal parameters. To illustrate this with a common example, here is how the square function might be defined in an
imperative programming language
In computer science, imperative programming is a programming paradigm of software that uses statements that change a program's state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program co ...
(
C):
int square(int x)
The variable x is a parameter which is replaced by the argument to be squared when the function is called.
In a
functional
Functional may refer to:
* Movements in architecture:
** Functionalism (architecture)
** Form follows function
* Functional group, combination of atoms within molecules
* Medical conditions without currently visible organic basis:
** Functional s ...
language (
Scheme A scheme is a systematic plan for the implementation of a certain idea.
Scheme or schemer may refer to:
Arts and entertainment
* ''The Scheme'' (TV series), a BBC Scotland documentary series
* The Scheme (band), an English pop band
* ''The Schem ...
), the same function could be defined:
(define square
(lambda (x)
(* x x)))
This is different in many ways, but it still uses the parameter x in the same way.
In Joy, the square function is defined:
DEFINE square dup * .
In Joy, everything is a function that takes a
stack
Stack may refer to:
Places
* Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group
* Blue Stack Mountains, in Co. Donegal, Ireland
People
* Stack (surname) (including a list of people ...
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
Quicksort is an efficient, general-purpose sorting algorithm. Quicksort was developed by British computer scientist Tony Hoare in 1959 and published in 1961, it is still a commonly used algorithm for sorting. Overall, it is slightly faster than ...
:
DEFINE qsort
mall
Mall commonly refers to a:
* Shopping mall
* Strip mall
* Pedestrian street
* Esplanade
Mall or MALL may also refer to:
Places Shopping complexes
* The Mall (Sofia) (Tsarigradsko Mall), Sofia, Bulgaria
* The Mall, Patna, Patna, Bihar, India
...
[]
[uncons [>] split]
[enconcat]
binrec.
"binrec" is one of Joy's many recursion, recursive combinators, implementing binary recursion. It expects four quoted programs on top of the stack which represent:
* the termination condition (if a list is "small" (1 or 0 elements) it is already sorted),
* what to do if the termination condition is met (in this case nothing),
* what to do by default (split the list into two halves by comparing each element with the pivot), and finally
* what to do at the end (insert the pivot between the two sorted halves).
Mathematical purity
In Joy, the
meaning function is a
homomorphism
In algebra, a homomorphism is a structure-preserving map between two algebraic structures of the same type (such as two groups, two rings, or two vector spaces). The word ''homomorphism'' comes from the Ancient Greek language: () meaning "sa ...
from the
syntactic monoid In mathematics and computer science, the syntactic monoid M(L) of a formal language L is the smallest monoid that recognizes the language L.
Syntactic quotient
The free monoid on a given set is the monoid whose elements are all the strings of ...
onto the
semantic
Semantics (from grc, σημαντικός ''sēmantikós'', "significant") is the study of reference, meaning, or truth. The term can be used to refer to subfields of several distinct disciplines, including philosophy, linguistics and comput ...
monoid
In abstract algebra, a branch of mathematics, a monoid is a set equipped with an associative binary operation and an identity element. For example, the nonnegative integers with addition form a monoid, the identity element being 0.
Monoids ...
. That is, the syntactic relation of
concatenation
In formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball". In certain formalisations of concatenat ...
of
symbol
A symbol is a mark, sign, or word that indicates, signifies, or is understood as representing an idea, object, or relationship. Symbols allow people to go beyond what is known or seen by creating linkages between otherwise very different conc ...
s maps directly onto the semantic relation of
composition
Composition or Compositions may refer to:
Arts and literature
* Composition (dance), practice and teaching of choreography
*Composition (language), in literature and rhetoric, producing a work in spoken tradition and written discourse, to include ...
of
functions. It is a
homomorphism
In algebra, a homomorphism is a structure-preserving map between two algebraic structures of the same type (such as two groups, two rings, or two vector spaces). The word ''homomorphism'' comes from the Ancient Greek language: () meaning "sa ...
rather than an
isomorphism
In mathematics, an isomorphism is a structure-preserving mapping between two structures of the same type that can be reversed by an inverse mapping. Two mathematical structures are isomorphic if an isomorphism exists between them. The word i ...
, because it is
onto
In mathematics, a surjective function (also known as surjection, or onto function) is a function that every element can be mapped from element so that . In other words, every element of the function's codomain is the image of one element of ...
but not
one-to-one; that is, no symbol has more than one meaning, but some sequences of symbols have the same meaning (e.g. "dup +" and "2 *").
Joy is a
concatenative programming language
A concatenative programming language is a point-free computer programming language in which all expressions denote functions, and the juxtaposition of expressions denotes function composition. Concatenative programming replaces function appli ...
: "The concatenation of two programs denotes the composition of the functions denoted by the two programs".
Its library routines mirror those of ISO
C, though the current implementation is not easily extensible with functions written in C.
See also
*
RPL
*
Concatenative programming language
A concatenative programming language is a point-free computer programming language in which all expressions denote functions, and the juxtaposition of expressions denotes function composition. Concatenative programming replaces function appli ...
References
External links
*
ZIP of Official Joy Programming Language Website (La Trobe University)Compiled informative collection on Joyimmediately executable Joy(GitHub-Archiv)
*
*
*
* {{cite journal, first=Stevan, last=Apter, title=Functional Programming in Joy and K, journal=Vector, url=http://www.vector.org.uk/archive/v214/joy214.htm, access-date=2011-02-28, archive-url=https://web.archive.org/web/20080828115345/http://www.vector.org.uk/archive/v214/joy214.htm, archive-date=2008-08-28, url-status=dead
mjoy, an interpreter in Delphi for machine drawing(Subset of Joy)
Programming languages
Concatenative programming languages
Stack-oriented programming languages
Functional languages
Academic programming languages
Programming languages created in 2001
2001 software
Dynamic programming languages
Dynamically typed programming languages
High-level programming languages