Replies: 2 comments
-
Hello! Thank you for the suggestion! Here are my initial thoughts. For the case you stated above, I can agree that it is arguably cleaner and more cohesive with other OO-styled languages. My hesitation is when it comes to storing procedure pointer/references on structures. If that procedure pointer does not take a Iterator :: struct (T: type_expr) {
data: rawptr
next: (rawptr) -> ? T
// ...
} If you tried to use the syntax you listed, I think there would be confusion as to what is/should be passed to the function. foo: Iterator(i32)
foo.next(foo.data) // Should this pass &foo first? or is it different because there is no `self` on the procedure reference? To keep things simple I took Lua's approach to this, which is to have a separate operator for calling a method. That way it is clear to the end user how arguments are being passed. OO in Lua for reference. Note, Onyx can't use the |
Beta Was this translation helpful? Give feedback.
-
Hello, thank you for the explanation. Iterator :: struct (T: type_expr) {
data: rawptr
next: (self) -> ? T
data: rawptr = self.data
// ...
next_other: (self, other: Iterator(T)) -> ? T
// ...
next_stat: (rawptr) -> ? T
// ...
}
// Calling the procs:
foo: Iterator(i32)
bar: Iterator(i32)
Iter32 :: Iterator(i32) //Alias
res1 := foo.next()
res2 := foo.next_other(bar)
res3 := Iterator(i32).next(foo.data)
res3 := foo::next(foo.data) //? maybe not good idea, not one way to call
res3 := Iterator(i32).next(bar.data)
res4 := Iter32.next(foo.data) I like the syntax and the design of Onyx. Maybe it's clearer to use |
Beta Was this translation helpful? Give feedback.
-
The operator "->" before a returning type in a procedure definition helps IMO to improve the readability of coding.
My question is: Could the operater "->" be replaced by "." for method calls? This would make the operator "->" unique for procedure defs.
I know Onyx is a data-oriented language, but if somebody prefers to include procedures to structs or unions, I think in this case the programer would like to use an oo-style call of methods.
self
or&self
(me or this) makes the coding clearer to read and understand.Beta Was this translation helpful? Give feedback.
All reactions