# New scope solution

**URL:** <https://discourse.julialang.org/t/new-scope-solution/16707>\
**Category:** Internals & Design\
**Tags:** proposal\
**Created:** [October 23, 2018, 8:58pm UTC](https://discourse.julialang.org/t/new-scope-solution/16707 "2018-10-23T20:58:16Z")\
**Posts on this page:** 1\
**Showing post:** 61

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [October 26, 2018, 8:43am UTC](https://discourse.julialang.org/t/new-scope-solution/16707/61 "2018-10-26T08:43:49Z")

</div>

> [@StefanKarpinski](#):
>
> Yes, it has to be a purely syntactic criterion. If you see a conditional, you consider all branches; if you see a loop you consider it being executed and not executed (for these purposes, a loop is equivalent to an `if` without an `else` ). If there’s any `@goto` we should probably require explicit annotation of anything that is assigned.

Forgive me if I’m wrong, but I thought `for` and `while` are syntactic sugar for `let` and conditional `@goto` (plus some `iterate` calls in the case of `for`); and `if`, `else`, etc are syntactic sugar for conditional `@goto`.

For that reason, the rule needs to work post-lowering and be clear on this lower level, as well as imply a sensible high-level rule (at the very least, the rule should be invariant under “partial lowering”, i.e. replacing high-level constructs by their low-level targets). Since the rule should be invariant under rearrangement of basic blocks, the second example follows. Or did I get this wrong?

In principle, your rule is on the control flow graph, not AST (that’s why it is more complicated, and also why it should be accompanied with tools to view the CFG; current tools to view the AST are not helpful anymore to debug scoping issues). So it is not syntactic, but close enough not to matter outside of corner cases.

PS.

> question what language construct `@goto` and `@label` is I could probably ask in future in another topic. 😉

Goto does what’s written on the label 😉 Sorry for the pun. A label labels a position in your code (so it does nothing). Goto goes (jumps) to a position; you need to label the position in order to tell goto where to jump to. This is super useful for e.g. breaking out of nested loops, and imho far cleaner and more readable than pulling along a bool (typical `found`) and doing multiple `found && break` and a final `if found ... else end`. Also, it is the low-level construct that loops are syntactic sugar for.

---

_[View the full topic](https://discourse.julialang.org/t/new-scope-solution/16707)._
