-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
Add at-isdefined #402
Add at-isdefined #402
Conversation
CI failures on macOS are unrelated. Is this something we want or would it be too misleading to have it only support a very limited subset of its 0.7 functionality on 0.6? |
The subset where this behaves the same as |
Okay. |
Not supported in Compat: JuliaLang/Compat.jl#402
* Avoid using `@isdefined` on Julia 0.6 Not supported in Compat: JuliaLang/Compat.jl#402 * Support Sys.is<os> on Julia 0.6 * Add Julia 0.6 to CI Note: Julia 0.5 was dropped from the CI as the REQUIRE file already specifies a minimum of Julia 0.6.
I think we should definitely have this because when updating code from 0.6 using |
No that (edit: the depwarn on 0.7) is unrelated. |
If |
Because it's a good replacement of |
In another word, if you really don't want to type Also, defining |
And yet another way you can call it In this case, this can be done (conservatively) if you make sure the macro is only used in global scope. I'm not sure the best way to do this but here's one of the very old tricks I've used before. julia> macro assert_global()
mod = isdefined(Base, Symbol("@__MODULE__")) ? __module__ : current_module()
@gensym dummy
quote
$(esc(dummy)) = nothing
if !isdefined($mod, $(QuoteNode(dummy)))
error("Not in global scope")
end
end
end
@assert_global (macro with 1 method)
julia> @assert_global
julia> let
@assert_global
end
ERROR: Not in global scope
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] macro expansion at REPL[0]:7 [inlined]
[3] top-level scope at REPL[2]:2 It's pretty ugly though........................... |
The Compat situation for `isdefined`/`@isdefined` is complicated; see JuliaLang/Compat.jl#402.
* Fixes for 1.0 * Fix another issue in deps/build.jl * Use `isdefined` on v0.6 The Compat situation for `isdefined`/`@isdefined` is complicated; see JuliaLang/Compat.jl#402. * Always listen to Yichao * using Compat inside submodule
Note that this is NOT functionally equivalent to
@isdefined
on 0.7; that isn't possible on earlier versions. Instead this defines@isdefined
to wrapisdefined
, which can only check for global variables.