Dynamic output

This is an example of the DDF primitive with a dynamic output porthole: the DownCounter primitive.

defprimitive
{
  name        { DownCounter }
  domain      { DDF }
  desc
  {
    Given an integer input with value N, produce a sequence of output
integers with values (N-1), (N-2), ... 1, 0.
  }

  input
  {
    name { input }
    type { int }
  }

  output
  {
    name { output }
    type { int }
    num  { 0 }
  }

  location { DDF library }

  go
  {
    // get input token from Geodesic
    input.receiveData();

    // generates output
    // the output only has a buffer of length one, so
    // we store one data token in the buffer and send it
    int in = int(input%0);
    for (int i = in - 1; i >= 0; i--)
    {
      output%0 << i;
      output.sendData();
    }
  }
}

The DownCounter primitive has a dynamic output porthole that will generate the down-counter sequence of integer data starting from the value read through the input porthole. The code in the go method is self-explanatory.