module main
struct Language { pub mut: score int = -1 name string @[required] }
fn (lr []Language) total() int { mut total := 0 for l in lr { if l.score > 0 { total += l.score } }
return total }
fn (lr []Language) average() int { return lr.total() / lr.len }
fn main() { racket := Language{98, 'racket'} // Simple arrays too! langs_arr := [racket, Language{102, 'ocaml'}] println(langs_arr) println(langs_arr.total()) println(langs_arr.average()) }
Remove
1. Whatever this is "fn (lr []Language) total() int {", why is there an ability to define a special function to an array? How do I know what overload is being used? If I change something from map to vector, how do I know there's nothing else that changes? Member function is just a sugar over regular functions? Great, remove member functions.
2. Why allow this? "racket := Language{98, 'racket'}" ? Why implicitly depend on ordering of parameter? Just use Language { .score = 98, .name = "racket", } Confusing order of evaluation? Great, just force it to be assigned exactly the same as the definition and force ordering that way.
3. Why remove the parenthesises " if l.score > 0 {"? In fact, I would even reject code that assumes any integer != 0 is True. Nope, you have to do the exact check every time. No more if (x) { }
4. Why allow default parameter? Why needing special syntax for @required?
I just want a very limited C with GC, pattern matching and algebraic data types. I don't even need generics.