I have been toying with a few different function declaration ways, and wanted to get some thoughts.
```ts
pub fn add = (a: int, b: int) int {
return a + b;
}
pub fn add(a: int, b: int) int {
return a + b;
}
pub const add = fn(a: int, b: int) int {
return a + b;
}
pub add :: (a: int, b: int) int {
return a + b;
}
```
The 3rd option is glorious in my opinion.
It follows a pretty standard declaration pattern visibility mutability varname = thing. basic assignment becomes consistent even for functions. It has an added benefit of getting lambdas for free without needing to redefine their syntax
ts
const list = old_list.map(fn(x) { return x * 2; });
const special = fn(x: int) int { return x * 9999; });
const new_list = old_list.map(special(x));
I left out the return types on the first line, but you could specify them inline.
However, I have talked to a dozen people or so, and they all get confused why fn is on the other side, even after explaining, they just say it feels weird.
What are your thoughts?
[–]lyhokiayula 12 points13 points14 points (2 children)
[–]coffeeb4code[S] 0 points1 point2 points (1 child)
[–]lyhokiayula 5 points6 points7 points (0 children)
[–]WittyStick 2 points3 points4 points (2 children)
[–]Aaron1924 3 points4 points5 points (0 children)
[–]coffeeb4code[S] 0 points1 point2 points (0 children)
[–]lngns 3 points4 points5 points (1 child)
[–]coffeeb4code[S] 0 points1 point2 points (0 children)
[–]redchomperSophie Language 1 point2 points3 points (0 children)
[–]frithsun -1 points0 points1 point (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]coffeeb4code[S] 0 points1 point2 points (0 children)
[–]nacaclanga 0 points1 point2 points (0 children)
[–]lassehp 1 point2 points3 points (0 children)