Cipherd@lemmy.ml to Programmer Humor@programming.dev · 1 month agofunctionslemmy.mlimagemessage-square44fedilinkarrow-up156arrow-down11file-text
arrow-up155arrow-down1imagefunctionslemmy.mlCipherd@lemmy.ml to Programmer Humor@programming.dev · 1 month agomessage-square44fedilinkfile-text
minus-squareunalivejoy@lemmy.ziplinkfedilinkarrow-up1·edit-21 month agoKotlin also lets you do fun x() = y()
minus-squarespongebue@lemmy.worldlinkfedilinkarrow-up0·1 month agoI have no idea why you’d need that especially since return y() is pretty easy, but… I want it! (Actually, I guess a super simple way of overloading a method, like fun x() = x(defaultValue) could be neat)
minus-squarecalcopiritus@lemmy.worldlinkfedilinkarrow-up0·1 month agoThis can also be a side product for code blocks being expressions instead of statements. In rust for example they are, so it’s not rare to see functions like: fn add_one(x: i32) -> i32 { x+1 } This lets you do amazing things like: let x = if y < 0.0 { 0.0 } else { y } which is the same as x = y < 0.0 ? 0.0 : y But is much better for more complex logic. So you can forget about chaining 3-4 ternary operations in a single line.
minus-square[object Object]@lemmy.worldlinkfedilinkarrow-up1·edit-21 month agoLisp programmers seeing these ‘amazing things’: But yeah, every time I’m trying to do a ternary in Lua, I miss being able to just throw in an if. Thankfully it can be amended with Fennel.
Kotlin also lets you do
fun x() = y()I have no idea why you’d need that especially since return y() is pretty easy, but… I want it!
(Actually, I guess a super simple way of overloading a method, like fun x() = x(defaultValue) could be neat)
This can also be a side product for code blocks being expressions instead of statements.
In rust for example they are, so it’s not rare to see functions like:
fn add_one(x: i32) -> i32 { x+1 }This lets you do amazing things like:
let x = if y < 0.0 { 0.0 } else { y }which is the same as
x = y < 0.0 ? 0.0 : yBut is much better for more complex logic. So you can forget about chaining 3-4 ternary operations in a single line.
Lisp programmers seeing these ‘amazing things’:
But yeah, every time I’m trying to do a ternary in Lua, I miss being able to just throw in an
if. Thankfully it can be amended with Fennel.