mreichelt / monkey-dart

Writing an interpreter for the Monkey 🐒 language in Dart
BSD 2-Clause "Simplified" License
28 stars 2 forks source link

Problem entering multiline function #6

Open jkleiser opened 7 years ago

jkleiser commented 7 years ago

I tried to enter the fibonacci function from https://interpreterbook.com, but your REPL didn't give me a prompt after I entered the final };. When I instead entered this one-liner, I could use the fib function without problem:

let fib = fn(x) { if (x==0) {0} else { if (x==1) {1} else { fib(x-1) + fib(x-2); }}};

Where is the magic "monkey" executable installed? Doing which monkey revealed nothing on my Mac. Thanks for this great fun!

mreichelt commented 7 years ago

@jkleiser Thanks! I had the same problem. I wrote @mrnugget about this, and he said it's coming in version 1.3. So stay tuned! :)

mrnugget commented 7 years ago

Small correction: the only thing that's coming in v1.3 is a fix for an endless loop that arises in the Go version, when a non-terminated block statement is entered on the REPL.

Multi-line is much harder to build than one might think and is probably out of the scope of the book. It would be interesting though to see if one could build a Monkey REPL using something like GNU Readline and get better support for the most common editing tasks.

jkleiser commented 7 years ago

If entering multi-line functions is a problem, how is @mrnugget able to load a function like the fibonacci? I tried monkey fibonacci.monk, but file arguments don't seem to be an option (in the Dart implementation) at the moment.

mreichelt commented 7 years ago

@jkleiser no, but I want to support them - see issue #5 :)