locked
Types Following Colons In Channel Definitions?

    Frage

  • The Axum Programmer's Guide contains this application:

    using System;
    using Microsoft.Axum;
    using System.Concurrency.Messaging;
    
    namespace Project06
    {
      schema Pair
    	{
        required int Num1;
        required int Num2;
    	}
      
      channel Adder
    	{
        input Pair Nums : int;
      }
      
    	agent AdderAgent : channel Adder
    	{
    		public AdderAgent()
    		{
          while(true)
          {
            var result = receive(PrimaryChannel::Nums);
            result <-- result.RequestValue.Num1 + result.RequestValue.Num2;
          }
    		}
    	}
    
      agent MainAgent : channel Microsoft.Axum.Application
      {
        public MainAgent()
        {
          var adder = AdderAgent.CreateInNewDomain();
          var correlator1 = adder::Nums <-- new Pair { Num1=10, Num2=20 };
          var correlator2 = adder::Nums <-- new Pair { Num1=30, Num2=40 };
          var sum1 = receive(correlator1);
          Console.WriteLine(sum1);
          var sum2 = receive(correlator2);
          Console.WriteLine(sum2);
          PrimaryChannel::ExitCode <-- 0;
        }
      }
    }
    
    

    What is the function of the "int" keyword to the right of the colon in the channel definition?

    Sonntag, 12. September 2010 22:54

Antworten

  • Hi Jeff,

     

    You'll find more about this in the language spec. (p7-8). Basically - and this is paraphrased from the spec. - it binds, more closely, a "reply value" to the port. Notice that in your code you're both sending, using the "<--" operator and receiving, using receive(), on the port Nums. You're only able to do this because we're explicitly saying that Nums has a reply value of type int.

    I am not 100% at which point the relationship is created between the lines:

     

    var result = receive(PrimaryChannel::Nums);
    result <-- result.RequestValue.Num1 + result.RequestValue.Num2;
    

    and the port, however. Maybe some one who actually knows can pick this up ;)

     

    P.S. Jeff, did you get my e-mail?

     

    Montag, 13. September 2010 09:53

Alle Antworten

  • Hi Jeff,

     

    You'll find more about this in the language spec. (p7-8). Basically - and this is paraphrased from the spec. - it binds, more closely, a "reply value" to the port. Notice that in your code you're both sending, using the "<--" operator and receiving, using receive(), on the port Nums. You're only able to do this because we're explicitly saying that Nums has a reply value of type int.

    I am not 100% at which point the relationship is created between the lines:

     

    var result = receive(PrimaryChannel::Nums);
    result <-- result.RequestValue.Num1 + result.RequestValue.Num2;
    

    and the port, however. Maybe some one who actually knows can pick this up ;)

     

    P.S. Jeff, did you get my e-mail?

     

    Montag, 13. September 2010 09:53
  • Thank you, Antony. I'll take a closer look at my code.

     

    PS. I don't see an email from you, but I welcome it ... send it to JEFFREY DOT FERGUSON AT GMAIL DOT COM for fastest results (note that its jeffREY and not jeffERY).

    Montag, 13. September 2010 21:58
  • Anthony's answer is correct -- this is the request-reply port. The receive method returns a correlator, which is a generic type. (This is why you really want to use 'var' here and not write the type explicitly -- it is rather unwieldy)
    Artur Laksberg - MSFT
    Mittwoch, 15. September 2010 03:04
    Moderator