Hacker News new | ask | show | jobs
by eggy 2828 days ago
I tried the live repl and input the fibonacci example:

  > (fn fib [n]
   (if (< n 2)
    n
    (+ (fib (- n 1)) (fib (- n 2)))))
which seemed to take, but then upon trying

  (print (fib 10))
it spit out the following:

  [string "return print(fib(10))"]:1: attempt to call a nil value (global 'fib')
Do I need to initialize fib before in the repl?
1 comments

It works if you run both expressions from file. There's a tutorial page that explains why this doesn't work in REPL. See "Locals are per-chunk" here: https://github.com/bakpakin/Fennel/blob/master/tutorial.md#g...
Thanks, that makes sense. I will also try making it a global value assuming global works in the online REPL.