What is the use of chords?

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

+3
source share
3 answers

The construct also exists in the language (as well as Polyphonic C #), at least according to [Wikipedia] ( http://en.wikipedia.org/wiki/Chord_(concurrency) .

The main use of chords, apparently, is associated with database programming (more precisely, join calculus ), which is not surprising, given that this is concurrency. Moreover, I am afraid that I do not know.

+2
source

concurrency. .

, :

, #, - , , . Cω ( / ) . , . . , , , , :

, . , ( ) . , . , , , , , , . , , . . , , , , , .

+2

Nemerle:

https://code.google.com/p/nemerle/source/browse/nemerle/trunk/snippets/ComputationExpressions/

:

 def upTo (n : int)
  {
    comp enumerable
    {
      mutable i = 0;
      while (i < n)
      {
        i ++;
        yield i
      }
    }
  }

  def manyTimes : IEnumerable [int] =
    comp enumerable
    {
      yieldcomp upTo(2);   // 1 2
      yield 100;           // 100
      yieldcomp upTo(3);   // 1 2 3
      yield 100;           // 100
      yieldcomp upTo(10);  // 1 2 3 .. 10
    }

def fn(n)
  {
    comp async
    {
      if (n < 20)
        returncomp fn(n + 1);
      else
        return n;
    }
  }
  def f(n1, n2)
  {
    comp async
    {
      defcomp n1 = fn(n1);
      defcomp n2 = fn(n2);
      return $"$n1 $n2";
    }
  }

private HttpGet(url : string) : Async[string]
{
  comp async
  {
    def req = WebRequest.Create(url);
    using (defcomp resp = req.AsyncGetResponse())
    using (stream = resp.GetResponseStream())
    using (reader = StreamReader(stream))
      return reader.ReadToEnd();
  }
}

A few more examples: (although the article is in Russian, but the code is in English :)) http://habrahabr.ru/blogs/programming/108184/

+2
source

Source: https://habr.com/ru/post/1710919/


All Articles