Search code examples
rascal

Equal objects with different identity?


Is it possible in Rascal to create clones of an object with different identity so that they are equal but not identical?


Solution

  • No, Rascal has value semantics.

    data X = x();
    bool alwaysTrue = x() == x();
    

    Even using closures, functions as data, you can not construct two distinguishable instances a and b which will still return true on a == b. The reason is that closures are never considered equal unless you have an alias pointing to the same instance.

    There is also no clone operation or anything like that. There are just expressions and their result is isomorphic to the expression tree that created them.

    Semantically Rascal does not guarantee that all values on the heap are actually shared or that they are just indistinguishable, so the memory optimisation perspective is left entirely to the run-time implementation.