Why does the Monkey repl panic at my program?
Por
GolangNewbie
0
Comentarios
Visto
106
veces
I have written a simple program in Monkey PL (see specification in https://interpreterbook.com/):
let fib = fn(x){
if(x>-1){
if(x<2){return x}
fib(x-1)+fib(x-2)
}
}
let max = fn(x,y){if(x>y){x} else {}}
let simple_faulhaber = fn(x){
if(x==0){
return 0
}
if(x>0){
x + simple_faulhaber(x-1)
}
}
When testing my functions in the repl, everything seems to work:
>> fib(13)
233
>> max(3,2)
3
>> simple_faulhaber(13)
91
max(simple_faulhaber(13), fib(13))*2
However, when I ask for an evaluation of max(simple_faulhaber(13), fib(13))*2
in the repl, the evaluator panics:
>> max(simple_faulhaber(13), fib(13))*2
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x4b7d57]
Can someone please explain to me, why?
interpreter read-eval-print-loop panic