Skip to content

Scoping: blocks allow binding and changing globals without declaring it so #7234

Closed
@tonyhffong

Description

In repl when I do this:

foo = 1
bar() = (foo=foo+1)
bar()

I get ERROR: foo not defined. So far so good.

But if I write it like this:

begin
  foo = 1
  bar() = (foo=foo+1)
  bar()
end

I get 2.

Wrapping it in block changes the behavior. Apparently the bar() inside a block can access foo without declaring it global. And outside the block, I can see foo, so foo is really a global.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions