Skip to content
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

Mystical order of "print" and "returned value" #12600

Closed
Sisyphuss opened this issue Aug 13, 2015 · 2 comments
Closed

Mystical order of "print" and "returned value" #12600

Sisyphuss opened this issue Aug 13, 2015 · 2 comments

Comments

@Sisyphuss
Copy link

The following code is a slight modification of 5th piece of code in the http://docs.julialang.org/en/latest/manual/variables-and-scoping/

x = 0
function foo(n)
  for i = 1:n
    x = i
    println(x)
  end
  x
end
foo(3)

The output is

0

2
3

The return value is 1.

This bug has something to do with #11065?

@StefanKarpinski StefanKarpinski added won't change Indicates that work won't continue on an issue or pull request and removed won't change Indicates that work won't continue on an issue or pull request labels Aug 13, 2015
@tkelman
Copy link
Contributor

tkelman commented Aug 13, 2015

@jakebolewski could you leave a few words at least when closing an issue, even an invalid one?

At the REPL when x is a global, the above prints 1, 2, and 3, and returns 0 for me. Seems intended and I don't think this is an issue, and this kind of question should go to julia-users first.

@Sisyphuss
Copy link
Author

ADD: I had some misunderstanding about the new output format of JuliaBox kernel v0.4.0-dev.
Here is the updated code:

x = 0
function foo(n)
  for i = 1:n
    x = i
    println("x:$x")
  end
  x
end
foo(3)

The output of JuliaBox looks like

        x:1

Out[2]: 0

        x:2
        x:3

The remaining thing is whether the returned value 0 is intended.

@Sisyphuss Sisyphuss changed the title Still variable scoping bug Mystical order of "print" and "returned value" Sep 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants