views:

240

answers:

2

Languages such as Nemerle support the idea of chords. I'd like to know what their practical use is.

+2  A: 

The construct also seems to exist in the language (as well as Polyphonic C#), at least according to Wikipedia.

The primary usage of chords appears to involve database programming (more specifically, join calculus), which is unsurprising given that it is a concurrency construct. More than that, I'm afraid I don't know.

Noldorin
+2  A: 

A chord is used for concurrency. The definition is available here.

The bit you are looking for:

In most languages, including C#, methods in the signature of a class are in bijective correspondence with the code of their implementations -- for each method which is declared, there is a single, distinct definition of what happens when that method is called. In Cω, however, a body may be associated with a set of (synchronous and/or asynchronous) methods. We call such a definition a chord, and a particular method may appear in the header of several chords. The body of a chord can only execute once all the methods in its header have been called. Thus, when a method is called there may be zero, one, or more chords which are enabled:

If no chord is enabled then the method invocation is queued up. If the method is asynchronous, then this simply involves adding the arguments (the contents of the message) to a queue. If the method is synchronous, then the calling thread is blocked. If there is a single enabled chord, then the arguments of the calls involved in the match are de-queued, any blocked thread involved in the match is awakened, and the body runs. When a chord which involves only asynchronous methods runs, then it does so in a new thread. If there are several chords which are enabled then an unspecified one of them is chosen to run. Similarly, if there are multiple calls to a particular method queued up, we do not specify which call will be de-queued when there is a match.

Richard Hein