Higher order message
   HOME

TheInfoList



OR:

A higher order message (HOM) in a computer
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
is a form of
higher-order programming Higher-order programming is a style of computer programming that uses software components, like functions, modules or objects, as values. It is usually instantiated with, or borrowed from, models of computation such as lambda calculus which make ...
that allows messages that have other messages as arguments. The concept was introduced at MacHack 2003 by Marcel Weiher and presented in a more complete form in 2005 by Marcel Weiher and Stéphane Ducasse. Loops can be written without naming the collections looped over, higher order messages can be viewed as a form of point-free or
tacit programming Tacit programming, also called point-free style, is a programming paradigm in which function definitions do not identify the arguments (or "points") on which they operate. Instead the definitions merely compose other functions, among which are co ...
.


Examples

In ordinary Smalltalk code, without using HOM, obtaining a collection of the employees that have a salary of 1000 would be achieved with the following code: salaried := employees select: each hasSalary: 1000 However, using HOM, it can be expressed as follows: salaried := employees select hasSalary: 1000. Here, select is a higher order message, and hasSalary: is understood to be called on the select message itself, rather than on its result. The Smalltalk language was not modified to implement this feature. Instead, select returns a message that reifies the select send, which then interprets the hasSalary: message. Another example is the use of future message sends in the
Croquet Project Croquet OS is a web-based operating system for creating three-dimensional apps with multi-user functionalities that run simultaneously on any device. Croquet can be used for communication, online gaming environments such as massively multipl ...
: (cube future:1000) addRotationAroundY:10. In this example, the future: message causes the addRotationARoundY: message to be sent to the cube object after 1 second.


Adoption

The reference implementation in
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXT ...
leverages the trait that in Objective-C, objects that don't understand a message sent to them, still get it delivered in a special hook method, called forward:. Higher order messaging was implemented in a number of languages that share this feature including
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called ...
and Smalltalk. ECMAScript Harmony's Proxies documentation specifically mentions higher order messages as an application for their Catchall Proxies.http://wiki.ecmascript.org/doku.php?id=harmony:proxies&s=proxy#higher-order_messages


Similar concepts in other languages

The programming language J distinguishes between
verb A verb () is a word ( part of speech) that in syntax generally conveys an action (''bring'', ''read'', ''walk'', ''run'', ''learn''), an occurrence (''happen'', ''become''), or a state of being (''be'', ''exist'', ''stand''). In the usual descr ...
s and
adverb An adverb is a word or an expression that generally modifies a verb, adjective, another adverb, determiner, clause, preposition, or sentence. Adverbs typically express manner, place, time, frequency, degree, level of certainty, etc., answering ...
s. Adverbs modify the functioning of verbs. This is similar to higher order messages (the adverbs) modifying the messages that follow (the verbs). In the Croquet example above, the addRotationAroundY:. message is still sent and has its normal meaning, but its delivery is modified by the future:1000 message, it will be sent sometime in the future.


References

{{reflist, 2 Programming paradigms