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

@generated @nloops #16

Closed
bjarthur opened this issue Apr 16, 2016 · 1 comment
Closed

@generated @nloops #16

bjarthur opened this issue Apr 16, 2016 · 1 comment

Comments

@bjarthur
Copy link

when using @generated in conjunction with @nloops, i get an UndefVarError(symbol("@nloops")) error when the built executable is run on the command line. the code runs fine when (a) either macro is used alone, or (b) the source is evaluated in the REPL. any ideas? see code below.

importall Base.Cartesian

# this does NOT work
@generated function foo{T,N}(A::Array{T,N})
  println(N)
  quote
    @nloops $N i A begin
      println(@nref($N,A,i))
    end
  end
end

#= but this DOES work
@generated function foo(A)
  println(A)
  quote
    println(A)
  end  
end    

# and so DOES this
function foo(A)
  @nloops 3 i A begin
    println(@nref(3,A,i))
  end
end
=#

function main()
  println("hello world!")
  foo(rand(3,3,3))
end

this blog seems relevant, but i don't entirely understand it.

@dhoegh
Copy link
Owner

dhoegh commented Jul 21, 2016

This is due to scoping of the module, when compiling the script. If you shall have the same experience in the REPL then you can only use the import statment. See https://github.com/dhoegh/BuildExecutable.jl/blob/master/test/test.jl where JSON is imported. Even if changing the import to using the functions from the JSON package should still be qualified with JSON.

@dhoegh dhoegh closed this as completed Jul 21, 2016
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

2 participants