C2 forum
General Category => Ideas => Topic started by: bas on April 15, 2017, 09:22:04 PM
-
With the current syntax, I think it's quite unclear when a function is a struct function. I would
like to try to make this more explicit. So hereby some ideas.
func void point_add(Point* p, int32 x) { .. } // current syntax
func void Point_add(Point* p, int32 x) { .. } // allow Upper-case as first char, so looks more like type Point
func void point_add[Point](Point* p, int32 x) { ..} /// hmm, 3 points in a row..no
func void point_add(Point* p, int32 x) @{structfunc} { ..} // via attribute
func void point_add(Point* p, int32 x) @{struct='Point'} { ..} // via attribute, nr 2
func void Point.add(Point* p, int32 x) { .. } // most explicit, via member operator
..
I like the last option best. The two arguments against it are:
- it's harder to see what the c- function name is (point_add in all cases). The is actually currently
the same for module attributes as well (Foo.bar() -> foo_bar) - The syntax breaks more with the ansiC style
What do you think?
-
how about something like this?
func[Point] void add(self, int32 x) { .. } // add the type to the func keyword, replace replace the instance with self
structfunc void add(Point* p, int32 x) { .. } // just say it's a struct func
The last option was also nice
EDIT:
suggestion No.3:
func void add(self*, int32 x) for Point { .. } // variation 1
func void add(Point* self, int32 x) for Point { .. } // variation 2