I agree that such a stronger guarantee would be much more useful. Apaarently, 
though, one cannot do that without some kind of lifetime tracking. The reason 
is the following: how do you prevent this?
    
    
    type IntBox = ref object
        i:int
    
    proc log(box:IntBox)=
        echo $box.i
        var foo = box
        foo.i = 2   # this is ok because `foo` is mutable
        # Strong guarantee is gone :(
    

This may seem like a simple case, but then consider
    
    
    type IntBox = ref object
        i:int
    
    proc evilModifier(box: var IntBox) =
        box.i = 2
    
    proc log(box:IntBox)=
        echo $box.i
        var foo = box
        evilModifier(foo)   # no local change in sight, and yet...
        # Strong guarantee is gone :(
    

So, without a way to track lifetimes at compile time, as it happens in Rust, 
one cannot prevent the modification of pointed objects. Of course, actually 
tracking this stuff introduces a lot of complexity in the language.

Reply via email to