Confusion about scope in try-catch blocks

I see it the other way around, if is the odd one out. So I sometimes wonder how come if doesn’t introduce local scopes.

3 Likes

Yeah, such kind of thing bit me as well.
And it works in reverse as well: let’s say there is a function which has a locally-defined function within it (maybe implicitly, via do-block or @spawn or @threads). Now, you have to carefully examine all variable names within the local function to avoid incorrect behavior or performance issues.

I liked the idea from this blog bost of reserving x = a for variable initialization / declaration and using another syntax (they propose set x = b although I’d prefer Pascal-esque x := b) for assignment. That would make an easy distinction which variables in a function or closure definition are meant to be local and which to be captured.

1 Like
1 Like

I haven’t thought of a linter support. Wow, it looks that if it would work, then an additional syntax for re-assignment is useful even with Julia 1.x.

1 Like