3 ms·
def fibonacci(n : UInt64) return 1_u64 if n <= 1 fib(n - 1) + fib(n - 2) end puts fib(46) Am I reading this wrong or should that start with `def
by tomc1985 6y ago
def fibonacci(n : UInt64)
return 1_u64 if n <= 1
fib(n - 1) + fib(n - 2)
end
puts fib(46)
Am I reading this wrong or should that start with `def fib(n : UInt64)`?
- adenozine 6y agoYou're absolutely right.
- xmly 6y agoThis could be a killer feature - smart inferred function name.
- de6u99er 6y agoUntil someone adds a method called fib (staying with the example of the thread) doing something completely different.
- entropicdrifter 6y agoDynamic method swapout during recursion! Who doesn't want that feature?
- saghm 6y agoAs a joke in college, I came up with the idea of a language that used fuzzy-matching to find the variable/function name with the closest match to the identifier used if an exact match wasn't found. This has the "fun" property where as long as a single variable is in scope, there are no undefined variable errors :)
- trenchgun 6y agoThis seems like a super fun idea