Creating variables dynamically at local scope is not possible (if you are calling `eval` inside a function: it does not work like that!)
Since the runtime can determine that the local variable is undefined as > evidenced by an appropriate error All compile-time undefined bindings become a runtime lookup from the enclosing (i.e. module) scope. The undefined error means that this lookup failed. On Tue, Jul 19, 2016 at 10:43 PM, Christopher Rinderspacher < [email protected]> wrote: > I, too, would like to be able to check whether local variables are > defined. In my case, I am parsing a file that doesn't allow redefinition of > a field. The natural way to do this is to check whether I've previously > assigned a variable with the content. > > The fact that isdefined only looks at the module scope is really > irrelevant to my use case. Since the runtime can determine that the local > variable is undefined as evidenced by an appropriate error, I wish I could > do the same within my function without some clunky try ... catch mehcanism. > > > On Monday, May 11, 2015 at 7:31:06 PM UTC-4, Juha Heiskala wrote: >> >> Hello, >> >> Am I missing something or doesn't isdefined detect local variables of a >> function? >> >> >> julia> foo()= begin bar=1; isdefined(current_module(), :bar); end >> foo (generic function with 1 method) >> >> julia> foo() >> false >> >> Best Regards, >> >> Juha >> >> julia version 0.3.5 >> >> julia> versioninfo() >> Julia Version 0.3.5 >> Commit a05f87b* (2015-01-08 22:33 UTC) >> Platform Info: >> System: Linux (x86_64-linux-gnu) >> CPU: Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz >> WORD_SIZE: 64 >> BLAS: libopenblas (NO_LAPACK NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY) >> LAPACK: liblapack.so.3 >> LIBM: libopenlibm >> LLVM: libLLVM-3.3 >> >
