C2 forum

General Category => Ideas => Topic started by: bas on April 15, 2017, 09:22:04 PM

Title: Struct Function declaration
Post 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.

Code: [Select]
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:

What do you think?
Title: Re: Struct Function declaration
Post by: magnusi on May 09, 2017, 07:40:09 PM
how about something like this?
Code: [Select]
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:
Code: [Select]
func void add(self*, int32 x) for Point { .. } // variation 1
func void add(Point* self, int32 x) for Point { .. } // variation 2