[e-lang] Capabilities and value types?

Kevin Reid kpreid at mac.com
Wed Nov 1 20:45:04 CST 2006


On Nov 1, 2006, at 20:19, Sandro Magi wrote:

> So, from a language perspective, a capability is an object reference;
> very simple to explain. But what about types with value semantics? ie.
> C# System.ValueType and structs.
>
> //structs are stack-allocated
> public struct /*class*/ Test {
>   bool enabled = true;
>
>   public void Run() {
>     while(enabled) {
>       Console.WriteLine("Still going..."); }
>     }
>     Console.WriteLine("Revoked!");
>   }
>   //t is a new COPY of Test
>   public static void RunTest(Test capToTest) {
>     new Thread(capToTest.Run).Start();
>     Thread.Sleep(1000);
>   }
>   public static void Main(string[] args) {
>     Test capToTest = new Test();
>     RunTest(capToTest);
>     //when a struct this disables the original instance,
>     //not the copy that RunTest() got
>     capToTest.enabled = false;
>     Console.ReadLine();
>   }
> }
>
> The above behaves differently when Test is a struct, and a class. As a
> class, the loop terminates. As a struct, it runs forever.

In E, we call this difference pass-by-proxy vs. pass-by-construction  
(ignoring the stack-allocation part).

Usually, however, one would not define a pass-by-construction object  
which creates independent copies of essential state like the above  
example; the two primary cases are:

   * a pass-by-copy object, where the object may not have mutable  
state (but may refer to mutable objects, and therefore the copy has  
proxies rather than near references if it was into another vat/thread)

   * an unum, where the newly constructed object ('presence') takes  
measures to keep its state synchronized with the original object.

> I'm not sure it's a huge deal other than "programmer beware", but in
> trying to map capabilities as access control to the language's
> semantics, I'm at a bit of a loss. Is "capToTest" a capability?

Yes. The copying behavior need not be considered fundamental; it can  
be seen as merely part of inter-thread communication behavior; that  
is, a (non-network) comm-system.

> Given value semantics, I would conclude that a variable bound to a
> struct either:
>
> 1. is not a capability
> 2. is a capability to an object whose behaviour is bound to the
> capability (ie. clone-on-capability-copy)

3. is a reference to an object which the inter-thread communication  
system chooses to treat specially.

-- 
Kevin Reid                            <http://homepage.mac.com/kpreid/>




More information about the e-lang mailing list