General Category > Ideas

Struct Function declaration

(1/1)

bas:
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.


--- Code: ---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

..

--- End code ---

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?

magnusi:
how about something like this?

--- Code: ---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

--- End code ---

The last option was also nice

EDIT:
suggestion No.3:

--- Code: ---func void add(self*, int32 x) for Point { .. } // variation 1
func void add(Point* self, int32 x) for Point { .. } // variation 2

--- End code ---

Navigation

[0] Message Index

Go to full version