richardhundt / shine

A Shiny Lua Dialect
Other
231 stars 18 forks source link

Would it be hard to add an interactive mode (REPL) option to nyanga? #37

Closed shortweekend closed 10 years ago

shortweekend commented 10 years ago

It's probably hard to have a real read–eval–print loop but what would be the easiest approach to an interactive mode? Thanks

Spoiler alert: People start asking for a REPL when a language is getting traction ;)

richardhundt commented 10 years ago

On 3/3/14 12:07 PM, shortweekend wrote:

It's probably hard to have a real read–eval–print loop but what would be the easiest approach to an interactive mode? Thanks

Evaluating statements and expressions is easy. You just read a line into a buffer, see if it compiles, if not assume that the statement is incomplete and repeat. The hard part is the scoping. In Nyanga, everything is lexically scoped. So if you did:

airy:nyanga richard$ ./repl
> class A end
> print(A)
caught:    src/lang/translator.lua:128: nyanga: (stdin):1: "A" used but
not defined

the problem is that once a chunk like class A end is parsed, it produces a function via loadstring and it gets evaluated with a fresh lexical environment. This means that you can't see previous declarations. I'd have to think about how to make this work for a repl in a way that isn't too intrusive to the compiler.

Reply to this email directly or view it on GitHub https://github.com/richardhundt/nyanga/issues/37.

richardhundt commented 10 years ago

On 3/3/14 12:07 PM, shortweekend wrote:

It's probably hard to have a real read–eval–print loop but what would be the easiest approach to an interactive mode? Thanks

Okay, we now have a repl. Just run nyanga with '-i' or without arguments.

— Reply to this email directly or view it on GitHub https://github.com/richardhundt/nyanga/issues/37.

shortweekend commented 10 years ago

Awesome! Now we're talking! :)