Infinite recursion and StackOverflowError in Julia

Written by Administrator on Sunday May 10, 2020

In order to evoke StackOverflowError in Julia it's enough to write a function, which result in infinite recursion. Let's see, how it works:

julia>

function foo(arg)
           if arg>1
               println("x")
           else
               foo(arg)
           end
       end

And now let's call foo() function with an argument:

julia> foo(1)

Result is predictable:

ERROR: StackOverflowError:
Stacktrace:
 [1] foo(::Int64) at ./REPL[7]:5 (repeats 80000 times)

infinite recursion in Julia : StackOverflowError

As you on the result of running a script, Julia is still trying to execute our infinite recursion 80.000 times. Such a persevering attempt! :)

Category: julia Tags: julia recursion infinite