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

if cond then works #6846

Closed
StefanKarpinski opened this issue May 14, 2014 · 5 comments · Fixed by #14756
Closed

if cond then works #6846

StefanKarpinski opened this issue May 14, 2014 · 5 comments · Fixed by #14756
Labels
breaking This change will break code needs decision A decision on this change is needed

Comments

@StefanKarpinski
Copy link
Sponsor Member

julia> if true then
           println("here")
       end
here

Should this be a undefined variable error?

@JeffBezanson
Copy link
Sponsor Member

I feel like this has been brought up a hundred times before but I can't find the references.

@StefanKarpinski
Copy link
Sponsor Member Author

If you replace true with false I have no problem with this working, but using an undefined variable – even in void context – seems like it should be an error.

@stevengj
Copy link
Member

Maybe this is a feature? This way we can make our code more polite by writing

if true please
     println("here")
end

We can even add an INTERCAL-like feature in which a program that does not contain please sufficiently often is rejected by the parser as impolite.

Seriously, though, I'm inclined agree with @StefanKarpinski that using an undefined variable in a void context should be an error. I'm finding a hard time imagining a practical use case for this.

@mbauman
Copy link
Sponsor Member

mbauman commented May 19, 2014

I was using this for inline comments before we got the #= block syntax:

julia> function foo(bar,baz)
         bar > 1 && (sometimes_frob_the_bar; bar+=1)
         but_always_quux_with_the_baz; baz*bar/2
       end
foo (generic function with 1 method)

julia> foo(2,3)
4.5

(I kid. +1 for errors here, but it's bigger than just if clauses.)

@stevengj
Copy link
Member

Right, it's any use of an undefined variable in a void context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code needs decision A decision on this change is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants