-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EvalContext discards context on recursion #93
Comments
This also extends into |
Now you say it .. yes. This is obviously incorrect! Thank you for the bug-report. If you want to have a stab at resolving it you're welcome, otherwise I'll look at it over the weekend. |
I think you should take a swing at it. I recommend just temp removing the |
I suspect this solution would get messy quickly, since EvalContext passes to evalBlockStatement, etc, etc. The better change is to add a call to "SetContext", and use that to update the global context variable - which defaults to context.Background, and only test that. There then wouldn't be any difference between Eval and EvalWithContext.
Possibly SetContext and the global variable can be local/package-local, rather than externally accessible. That preserves the current API. |
I wouldn't have a global variable context, that's pretty bad practice. Changing unexported functions isn't a breaking change. EDIT: Also it looks like |
Yeah having the global is not great - the issue with this implemetnation is that everything's global, more or less, there should be a struct to start state of the interpreter and mediate access appropriately. Still it looks like your PR does all the right things and I'll merge that. Thanks for taking the time to report the issue and resolve it. |
NP. I've been trying to complete my own monkey interpreter for a while and kept getting sidetracked, and seeing your repository has helped a lot in my own pursuit, especially around the part where I parse my tokens into the AST for then further execution. |
evaluator.EvalContext
has some points where it callsEval
, which then just callsEvalContext
with a background context, thus dropping the original context passed to it. This should be fixed so it instead callsEvalContext
with the provided context.EG: https://github.com/skx/monkey/blob/master/evaluator/evaluator.go#L56
The text was updated successfully, but these errors were encountered: