• entries
    359
  • comments
    237
  • views
    188610

Tangent: this-properties

Sign in to follow this  

150 views

Just a little work today. I implemented something mildly weird. For those familiar with C++, Tangent supports a form of operator(). It's something like:


public class foo{
public this()=>void{
print "foo!";
}
}

public static main()=>void{
local foo aFoo = new foo;

aFoo();
}



And it's used for the normal sort of functor stuff that C++ uses it for.

What I implemented today was a similar beast for properties:


public class intProperty{
private int x;

public int this{
get{
return(x);
}
set{
x = value;
}
}
}

public static main()=>void{
local intProperty x = new intProperty;

x = 5;
print x;
}



Not very thrilling. Eventually though, I want to use this mechanism to create stuff like reusable properties that have an event that is triggered when the setter is called. It'll also be used for things often relegated to implicit conversions.

I need to figure out a good way to allow the programmer to disambiguate member access on the property rather than it's value member access, but that's not a huge priority. I don't expect that scenario to arise often.
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