[e-lang] Capabilities and value types?

Sandro Magi naasking at higherlogics.com
Wed Nov 1 21:29:24 CST 2006

Kevin Reid wrote:
> Usually, however, one would not define a pass-by-construction object
> which creates independent copies of essential state like the above
> example;

I'm curious about the above as it's not clear to me, but I don't think
it's essential to my question, so I'll research it later.

> 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.

This sounds similar to a proxy. Would the semantics be similar to a
checked out source repository that must merge changes from and submit
changes to a central repository?

>> 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

C# ValueType semantics are not related to threading, it's purely the
semantics of value types (as in #2). An even simpler example:

public struct /*class*/ Test {
  bool enabled = true;

  public static void Main(string[] args) {
    Test capToTest = new Test();
    Test newCopy = capToTest; //capability copy copies the object
    newCopy.enabled = false;
    Console.WriteLine(capToTest.enabled); //prints "true"
    Console.WriteLine(newTest.enabled); //prints "false"

If Test were a class, they would both print false. "new Test()" isn't
even necessary, as the mere declaration of a ValueType variable
pre-allocates the space on the stack and initializes the struct's fields
with their default values. The following is identical to the first two
lines in Main() above:

    Test capToTest; //stack space allocated and object initialized
    Test newCopy = capToTest; //capability copy copies the object

Given your explanation above, the .NET semantics for ValueTypes are
pass-by-copy with mutable state, correct?

Thanks for the clarification on capabilities and object copy semantics.


More information about the e-lang mailing list