Open Magnogen opened 2 years ago
Very interesting. This perhaps goes to dangerous and brave heights not even known before to DreamBerd. But you make a good point: goto
is evil bad practice, and return
is just another type of goto
! Look at this:
function fizzbuzz(n) => {
if (n % 3 = 0) return "Fizz"!
if (n % 3 = 0) return "Buzz"!
if (n % 3 = 0 & n % 5 = 0) return "FizzBuzz"! // BUG: This line never runs...
return n!
}
Maybe return
could be a variable that gets assigned in every function body. FIXED:
function fizzbuzz(n) => {
return = n!
if (n % 3 = 0) return = "Fizz"!
if (n % 3 = 0) return = "Buzz"!
if (n % 3 = 0 & n % 5 = 0) return = "FizzBuzz"!
}
PS: remember to indent with 3 spaces when writing DreamBerd :)
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 ...
withname_of_function() = ...
! There are a few interesting consequences of this, but could it work? Maybe...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!
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!
I enjoyed doing this little (maybe not so little) write-up! What do you think?