Not logged inOpenClonk Forum
Up Topic General / Feedback and Ideas / Using the point operator for function calls in C4Script
- - By Fulgen [at] Date 2016-09-06 12:54
How about using the point operator for function calls in C4Script? After introducing the point operator for proplist access, I often mistake them, also because C++ uses the point operator for calls, except if using pointers.
Parent - By Maikel Date 2016-09-06 15:46
That would break all third-party content and most of all I think all the main developers are pretty used to ->. I would very much oppose such change.
Parent - By Luchs [de] Date 2016-09-06 16:29
I don't think the change is worth the trouble.

- We'd have to keep -> in any case for compatibility reasons (see Maikel).

- -> always starts a function call, and . always starts a proplist access. This likely makes the parser simpler.

- You already can use the point operator for calls, by rewriting foo->Bar(1, 2, 3) to Call(foo.Bar, 1, 2, 3) (or maybe you need foo->Call(foo.Bar, 1, 2, 3), not sure)
Parent - - By Sven2 [us] Date 2016-09-06 19:26
I think it's a sensible change. We could keep -> for backwards compatibility for a while and emit a warning.
Parent - - By Marky [de] Date 2016-09-06 19:57
How do you make a difference between accessing a function definition this.foo and actually calling it? Just by the brackets: this.foo, this.foo()?
Parent - By Luchs Date 2016-09-06 21:01
This approach isn't uncommon, see for example JavaScript. If we do this, it would also be nice if parentheses would work as "function call operators" everywhere, as in (this.foo)(); and var bar = this.foo; bar();
Parent - - By Zapper [de] Date 2016-09-06 20:33
Mh, why is it a sensible change? Imo it's just as sensible as saying "->" is for function calls and "." is for property reading/writing.

(I am not particularly for or against that at the moment; I don't see why it's objectively better, though)
Parent - By Sven2 [us] Date 2016-09-06 23:04
Right now, to access local functions and properties:
foo(bar)
For remote access in context "other":
other->foo(other.bar)
After the change:
other.foo(other.bar)

The simplification would be that to go from a local lookup to another context lookup, you have to prefix "other.". That's easier to remember than prefixing "other->" for functions and "other." for properties.

I think Guenther was asking exactly this question at the time and we (me included) voted against it though. Decades of C4Script momentum are hard to stop.
Parent - By Maikel Date 2016-09-06 21:26
Having two option just makes scripts different and harder to read. Also the -> resembles nicely that an object is making the call.
- - By Caesar [de] Date 2016-09-07 00:34
Btw, could someone explain this stuff to me:

If I do foo->bar(), and bar is a function in a proplist foo, what will be the object context of that call? Does that change if foo is not a proplist but (additionally) an object?

Also, my opinion is that foo.bar->blubb.gar() should be something meaningful, namely calling the function blubb.gar with the object context foo.bar (where blubb and foo are just proplists having their properties gar and bar accessed, one being an object/proplist, the other a function). I like it because there's nothing implicit about it, but I hate it because it's awfully complex and hard to read.
Parent - By Sven2 Date 2016-09-07 15:25

> If I do foo->bar(), and bar is a function in a proplist foo, what will be the object context of that call? Does that change if foo is not a proplist but (additionally) an object?


'this' will be foo. Ordinary proplists can also be contexts iirc.

> Also, my opinion is that foo.bar->blubb.gar() should be something meaningful, namely calling the function blubb.gar with the object context foo.bar


That would be nice and would indeed be an application of having the distinct . and -> operators.

You can also just do foo.bar->Call(blubb.gar) right now of course.
Up Topic General / Feedback and Ideas / Using the point operator for function calls in C4Script

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill