Reputation: 329
I'm trying out Julia and the DataArray package. I want to initialize, with zeros, a data array of a size given by an integer stored in a variable 'n'. However, I get an error message "ERROR: n not defined" (even though it clearly seems to be).
The following is a small example:
using DataArrays
n = 8
@data(zeros(Float64,n))
which for me produces the above error message. (Note that
using DataArrays
@data(zeros(Float64,8))
does work.)
Any ideas?
Upvotes: 2
Views: 1166
Reputation: 3642
n = 8
float64(DataArray(zeros(Float64 ,n)))
Will get you where you're going. The @data
macro kind of sucks and the only use I can think for it is when writing tests if you want to say something like
x = @data([1,2,3,NA])
Normally the list constructor will crap on you. However this does also work:
x = float64(DataArray(Any[1,2,3,NA]))
So, I don't know. Stay away from that @data
macro. Macros in general have a hard time seeing your local variables or functions and variables from other Modules. It's a problem that can clearly be worked around since @show
mostly works, but many macros have this and other problems. Macros in general are kind of suspect.
Upvotes: 1