V is a very young language, that's why it could maybe support recent concepts like the infix functions.
Basically, an infix function is :
user.can_register(16), it can be called by user can_register 16)It increases readability.
Also, some operators like in could be infix functions instead of operators (so anyone could create "operators" like not_in or anything else).
The idea is well described here: https://kotlinlang.org/docs/reference/functions.html#infix-notation
In V, a classic method could be described as :
struct User {
age int
}
fn (u User) can_register(age_min int) bool {
return u.age > age_min
}
user := User{age: 10}
ok := user.can_register(16) // ==> "false"
An infix function could be simply declared the same way, but adding the keyword infix, like this :
struct User {
age int
}
infix fn (u User) can_register(age_min int) bool {
return u.age > age_min
}
user := User{age: 10}
ok := user can_register 16 // ==> "false"
The infix functions can be combined with lambda (see #1066)
Example :
ints := [1, 2, 3]
doubled_ints := ints.map(fn (x int) {
return x * 2
})
//could be replaced by
doubled_ints := ints map { i ->
return i * 2
}
Personally I love the idea, but I don't know that it coincides with v's philosophy of "one way to do things"
Lets just have “one way to do things", no more “infix” please. :)
user can_register 16
I think you need a better example, that looks like infix abuse to me.
The map example would be:
doubled_ints := ints map fn(i){
return i * 2
}
I'm not sure that infix is the right feature here, because it doesn't work for more than one argument:
ints.reduce(1, fn (acc, e) acc *= e)
Thanks, but this complicates the language and adds another way of declaring/calling methods. This goes against the philosophy of V.
Most helpful comment
Personally I love the idea, but I don't know that it coincides with v's philosophy of "one way to do things"