EDIT: There was no problem, I was simply not aware that a
try/catch statement introduces a local scope. Pluto and reactivity are solid <3
By using a try/catch statement in a pluto notebook, I can define a variable
test two times:
It is clear that the definition inside the try statement actually has no effect, despite not erroring.
I guess that try/catch is a nasty case to handle for interactivity. But the current way things work is silently not working, which I think we all agree is the worst way to handle anything.
Can Pluto handle try/catch statements? Or should they throw a warning in Pluto notebooks?
try introduces local scope (independently of Pluto):
test = 2
ERROR: UndefVarError: test not defined
test inside the
try is just like a local variable
test inside a
for loop-- it doesn’t affect the global scope.
Alright, that makes sense. So adding a
global before the definition should make things work?
Depending what you want, that could work. You could also do something like
test = try
test is not defined within the
try block, but rather is a global whose value is given by whatever the
try block evaluates to.
That is also quite elegant. Thanks a lot!
You can also simply put
local test in front of the try catch block.