Jump to content

Higher order message

From Wikipedia, the free encyclopedia

A higher order message (HOM) in a computer programming language is a form of higher-order programming that allows messages that have other messages as arguments. The concept was introduced at MacHack 2003[1][2] by Marcel Weiher and presented in a more complete form in 2005 by Marcel Weiher and Stéphane Ducasse.[3] 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.

Examples

[edit]

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 | 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:[4]

 (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

[edit]

The reference implementation in Objective-C 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 and Smalltalk.[5][6]

ECMAScript Harmony's Proxies documentation specifically mentions higher order messages as an application for their Catchall Proxies.[7]

Similar concepts in other languages

[edit]

The programming language J distinguishes between verbs and adverbs. 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

[edit]
  1. ^ "MacHack HOM Presentation" (PDF).
  2. ^ "MacDevCenter.com: Higher-Order Messages in Cocoa". November 12, 2004. Archived from the original on 2004-11-12.
  3. ^ Proceeding DLS '05 Proceedings of the 2005 symposium on Dynamic languages [1]
  4. ^ "Croquet System Overview, page 6" (PDF). Archived from the original (PDF) on 2012-04-26. Retrieved 2012-05-18.
  5. ^ "SqueakSource". www.squeaksource.com.
  6. ^ [2] Archived 2012-02-03 at the Wayback Machine
  7. ^ http://wiki.ecmascript.org/doku.php?id=harmony:proxies&s=proxy#higher-order_messages