• entries
    359
  • comments
    237
  • views
    188610

Tangent: this-properties part 2.

Sign in to follow this  

123 views

I'm not sure what the deal is with my new car. It must look fast or something. I've gotten pulled over for speeding more times in the past week with the new car than I did in 9 years with the old. Warnings only thankfully. It's not as though I'm driving any differently. Seriously troopers, it's probably not the best use of your time to profile against station wagons; even sporty ones.

Anyways, the last example I posted on this-properties was not quite complete. If you tried to assign one to another, you'd get an ambiguity error since the compiler couldn't figure out if you wanted to assign the property or the contents. So I quickly implemented an Unassignable type, that essentially prevents a reference from being modified after it's been allocated. Useful for this exercise, and for a few others I'd imagine. It'll cause some weirdness once template methods are implemented, but I'll deal with that bridge when it comes along.

The test code for this change (pardon the poor naming):


public class field: Unassignable{
private int x;
public int this{
get{
return(x);
}
set{
x = value;
}
}
}

public static main()=>void{
local field n;
local field p;

p=5;
n=p;
print n;

}




Before, the 2nd to last line would cause error. Technically the declaration/initialization itself would produce error since it goes through and does proper assignment as well.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now