-
Notifications
You must be signed in to change notification settings - Fork 10
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
Variable capture does not workout without encapsulation #148
Comments
Thank you for catching this! The current Parla captures variables within a function. We will discuss and fix this semantic (or let you know) soon. For now, please use "Fun" way |
Duplicate of #67 ? |
It is mentioned indirectly in the first tutorial: "Notice that we do not directly create Parla tasks in the global scope. Instead, we define a main function and create our tasks there. To ensure correct capture of local variables, Parla tasks should not be defined in the global scope." But I agree we could be more clear about this. |
At the moment there is no easy way to fix this. To fix the capture semantics we would have to copy the specific variables needed from the globals array. This would both need a hack of the Python byte code (currently outside of my skillset) and/or possibly linear costs in the size of globals. Personally, I think Parla API should probably eventually be changed to make tasks functions instead of code block capture to avoid these incompatible semantics between local and global variables. But open to any ideas of other ways to work around it. |
Thanks for the clarification. I agree, the syntax is confusing. Instead, it should be a function call or a function annotation to force the user to encapsulate the code Parla(fun)
# or
@Parla
def fun(): |
I agree with that this semantic is confusing. But this was a design choice and has pros and cons. |
In the following code, variables are not captured if I write code directly inside the Parla context. Not sure if this is intended behavior, if so it is not documented anywhere and certainly should be mentioned in the first tutorial.
This program outputs:
Using nonlocal in the first part also leads to a syntax error.
The text was updated successfully, but these errors were encountered: