Alex Turner <ajturner@armature.com> wrote:
> #!/usr/bin/bash
> declare -i n
> n=0
> r()
> {
> echo $n
> n=n+1
> r
> }
> r
>
> The above script will crash bash dew to a segmentation violation.
How did you expect it to behave differently? Your computer has only a
finite amount of memory; infinite recursion will eventually use it
all, and continue trying to use more. A real functional program would
not use infinite recursion and would (probably) not encounter this
problem. bash could be changed to give an error message instead of
crashing, but I imagine that might have a significant performance
impact.
paul