I'm reading this introduction to Polyphonic C# and the first page contains this example:
Example: A Simple Buffer
Here is the simplest interesting example of a Polyphonic C# class:
public class Buffer { public String get() & public async put(String s) { return s; } }
I don't get it at all.
What does the & between methods get() and put() signify?
That's not legal C#. That's polyphonic C#. That's a research project from Microsoft. It's a shame it's not precisely defined1 but the point is this:
In Polyphonic 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.
So & is "binding" those methods together into a chord which won't be invoked until all the methods in the chord are invoked.
A little further along in the same article:
These two methods appear (separated by an ampersand) in the header of a single chord, the body of which consists of the return statement. Now assume that
bis an instance ofBufferand that producer and consumer threads wish to communicate viab. Producers make calls toput(), which, since the method is asynchronous, do not block. Consumers make calls toget(), which, since the method is synchronous, will block until or unless there is a matching call to put(). Oncebhas received both aput()and aget(), the body runs and the argument to theput()is returned as the result of the call toget(). Multiple calls toget()may be pending before aput()is received to reawaken one of them and multiple calls toput()may be made before their arguments are consumed by subsequentget()s.
1: But, such is the nature of cutting edge. I do get it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With