A cool way to do function returns, without the return
keyword! (adapted from hawkw/HawkLang.md)
The idea
(Function syntax hasn't really been specified yet, so I'll just do what's showed in the booleans section)
The premise is, replace return ...
with name_of_function() = ...
! There are a few interesting consequences of this, but could it work? Maybe...
function fib(x) => {
if (x <= 0) fib(x) = 0!
if (x == 1 || x == 2) fib(x) = x!
fib(x) = fib(x - 1) + fib(x - 2)!
}
This also has the wonderful consequence of having to rename all of your return statements if you rename the function!
An interesting way to extend this is by using conditions in the argument slots for implicit if
s!
This code does exactly the same thing as the one above, but makes the programmer think of it in a different way!
function fib(x) => {
fib(x <= 0) = 0!
fib(x == 1 || x == 2) = x!
fib(x) = fib(x - 1) + fib(x - 2)!
}
I'm not sure what would happen if another function is used for the return statement, maybe it'll return a value from that one, if it's nested in it? Idk that'd be pretty weird... Maybe a bit too weird even for berds!!1!
function a() => {
b()!
a() = "I dont run?!"!
}
function b() => {
a() = "I do!"!
"but then does this output?"?
b() = "returned from b()"!
}
a()?
// but what would happen with
b()?
// an error?
// printing "but then does this output?" and then outputting "returned from b()"?
// would it depend on if `b()` was called by `a()`?
// side note: github syntax highlight really doesnt like using ! instead of ; lol
I enjoyed doing this little (maybe not so little) write-up! What do you think?