julia> function fib(n::Int)
n<0 && error("n must be non negative")
n==1 && return 1
fib(n-1) + fib(n-2)
end
fib (generic function with 1 method)
julia> fib(2)
ERROR: n must be non negative
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] fib(::Int64) at .\REPL[13]:2
[3] fib(::Int64) at .\REPL[13]:4 (repeats 2 times)
[4] top-level scope at none:0
Thanks !
Still, I find it weird the error() message was triggered.
This got me thinking my coding of this line was wrong and that it was acting as < or = :
I had
julia> fib(0)
ERROR: n must be non negative
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] fib(::Int64) at .\REPL[37]:2
[3] fib(::Int64) at .\REPL[37]:4
[4] top-level scope at none:0