tokiwa-software / fuzion-idioms

Idioms from https://www.programming-idioms.org implemented in the Fuzion language.
Other
3 stars 2 forks source link

add idiom 301 Recursive Fibonacci sequence #153

Closed simonvonhackewitz closed 1 week ago

simonvonhackewitz commented 2 weeks ago

Not sure if there is a better way to do this. The idiom description says that naive recursion is extremely inefficient for this task, but the other language do it similarly.

simonvonhackewitz commented 2 weeks ago

I've added a tail recursive version as a second example. I've only included a running example for it and left out the code version, take a look at the html file and let me know if a different way is preferred.

simonvonhackewitz commented 2 weeks ago

Also both version don't work for negative numbers. Does that matter for an idiom?

And if so, whats the best way to handle it? Change the argument type to u32, then it will have a different type than the default type of constants or loop variables, or add a precondition?

maxteufel commented 1 week ago

Either change the type to u32 and deal with the consequences, or use a precondition.