Reputation: 724
I'm trying to call this macro from within a method where the parameters to the macro are passed in to the method. It works fine when I call it directly but there is something about the macro expansion which is preventing the variables lat and lon from being correctly used in the macro.
The macro I'm calling is @select here: https://github.com/Alexander-Barth/NCDatasets.jl/blob/4e35e843a53cdcff7f7ef66ebc3ceab1ee1e860b/src/select.jl#L54-L168
and here is the function where the lat and lon variables are not being expanded correctly
function data_for_lat_lon(ds, region, lat_lon_pair)
println("have latlon piar ", lat_lon_pair)
lat = lat_lon_pair[1]
lon = lat_lon_pair[2]
data = []
if(ArchGDAL.contains(region[1], ArchGDAL.createpoint(lon, lat)))
println(lat, " ", lon)
#the below call fails when called in this way
single_lat_lon = NCDatasets.@select(ds, latitude==$lat && longitude==$lon)
for (varname, var) in single_lat_lon
if varname in ["latitude", "longitude", "time"]
continue
end
push!(var_names, varname)
push!(data, Array[single_lat_lon[varname]][1][:])
end
return reduce(hcat, data)'
end
end
This is the error & stack trace I get when calling it:
MethodError: no method matching (::NCDatasets.var"#154#155")(::Float64)
The applicable method may be too new: running in world age 32645, while current world is 32646.
Closest candidates are:
(::NCDatasets.var"#154#155")(::Any) at none:0 (method too new to be called from this world context.)
Stacktrace:
[1] _broadcast_getindex_evalf
@ .\broadcast.jl:670 [inlined]
[2] _broadcast_getindex
@ .\broadcast.jl:643 [inlined]
[3] getindex
@ .\broadcast.jl:597 [inlined]
[4] copy
@ .\broadcast.jl:899 [inlined]
[5] materialize
@ .\broadcast.jl:860 [inlined]
[6] findall(testf::NCDatasets.var"#154#155", A::Vector{Float64})
@ Base .\array.jl:2311
[7] macro expansion
@ C:\Users\scott\.julia\packages\NCDatasets\sLdiM\src\select.jl:242 [inlined]
[8] data_for_lat_lon(ds::NCDatasets.MFDataset{DeferDataset, 1, String, NCDatasets.DeferAttributes, NCDatasets.DeferDimensions, NCDatasets.DeferGroups}, region::DataFrameRow{DataFrame, DataFrames.Index}, lat_lon_pair::Tuple{Float64, Float64})
@ Main .\In[46]:8
[9] top-level scope
@ .\In[50]:3
[10] eval
@ .\boot.jl:368 [inlined]
[11] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1428
I'm fairly confident this has something to do with the concept of "hygiene" and variable expansion with a macro but I'm new enough to julia to not understand what needs to be done in my calling function to resolve this. I have reveiwed this question but am not sure it applies to this case: How to pass variable value to a macro in julia?
Thanks!
Upvotes: 3
Views: 111
Reputation: 724
Turns out the issue was unrelated and was a known issue in julia: https://discourse.julialang.org/t/how-to-bypass-the-world-age-problem/7012
Upvotes: 1