Joy (programming language)

ImprimirCitar

The Joy is a functional programming language that was produced by Manfred von Thun of La Trobe University in Melbourne, Australia. Joy is based on function composition instead of lambda calculus. It has turned out to have many similarities to the Forth language, due less to design than to some sort of parallel and convergent evolution.

Operation

Joy is unusual (except for functional and some esoteric languages) in its lack of a lambda operator and thus no formal parameters. To illustrate this with a common example, we show how the function square can be defined in an imperative language (C):

 int square(int x) { return xx; !

The x variable is a formal parameter that is substituted for the value to be squared when the function is called. This same function defined in a functional language (Scheme) would result:

 (define (square x) (x x)

This is different in many ways, but it still uses the formal x parameter in the same way. This same function would be defined in Joy as follows:

 DEFINE square == dup *

In Joy, everything is a function that takes a stack as an argument and returns a stack as a result. For example, the symbol 5 is not, as it may appear, an integer constant, but a short program that push the number 5 onto the stack.

  • The operator dup simply duplicate the top element of the stack pushing (push) a copy of this element.
  • The operator * extrae (pop) two stack numbers and push (pushYour product.

So this square function definition makes a copy of the top element and then multiplies the two top elements, leaving the square in the original top element on the stack. There is no need for a formal parameter at all. This design makes the Joy language concise and powerful, as this definition of quicksort shows:

 DEFINE qsort ==
[small]
[]
[uncons [105] split]
[[swap] dip cons concat]
binrec.

binrec is one of Joy's many recursive combinators. binrec expects four programs indicated at the top of the stack:

  • the termination condition, if a list is "small" (small) (small) (small 1 or 0 elements) is already ordered,
  • what to do if the condition of termination is fulfilled (in this case nothing),
  • what to do by default (divide the list in two halves comparing each element to the pivot),
  • and finally what to do at the end (insert the pivot between the two classified halves).

Mathematical purity

In Joy, the meaning of a function is a homomorphism from the syntactic monoid to the semantic monoid. That is, the syntactic relationship of the concatenation of symbols maps directly onto the semantic relationship of the composition of functions. It is a homomorphism rather than an isomorphism because it is over but one to one, i.e. some sequences of symbols have the same meaning (eg dup + and 2 *) but no symbol has more than one meaning.

Joy manages to be practical and potentially useful, unlike the otherwise similar Unlambda. Its library of routines mirrors those of ISO C, although the current implementation is not easily extensible with functions written in C.

Contenido relacionado

ISO 3166-2:JP

Main article: ISO...

Turbo Pascal

Turbo Pascal is a software development system that includes a compiler and an integrated development environment for the Pascal programming language...

Microsoft encarta

Microsoft Encarta is a discontinued digital multimedia encyclopedia published by Microsoft Corporation between 1993 and 2009. As of 2008, the complete English...
Más resultados...
Tamaño del texto:
Copiar