include evaluates at top-level, so this would only work if foo were a
global variable. It not possible to include in a function context for the
same reason it is not possible to eval in a function context.
Simon
On Thursday, June 26, 2014 1:03:00 PM UTC-4, Tomas Lycken wrote:
>
> I have the following two files:
>
> *includetest1.jl*:
>
> module IncludeTest
>
> function testinclude()
> foo = "foo"
> println(foo)
> include("includetest2.jl")
> end
>
> end
>
> *includetest2.jl*
>
> println(foo)
>
> If I now try to execute this the function from the REPL, I get errors
> stating that foo is not defined:
>
> julia> include("includetest1.jl")
>
> julia> IncludeTest.testinclude()
> foo
> ERROR: foo not defined
> in include at boot.jl:244
> while loading [...]/includetest2.jl, in expression starting on line 1
>
> I thought include was supposed to just insert the contents of the file in
> whatever context you’re in? If include is not the way to do this, is
> there another?
>
> For completeness:
>
>
> julia> versioninfo()
> Julia Version 0.3.0-prerelease+3884
> Commit 3e6a6c7* (2014-06-25 10:41 UTC)
> Platform Info:
> System: Linux (x86_64-linux-gnu)
> CPU: Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz
> WORD_SIZE: 64
> BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
> LAPACK: libopenblas
> LIBM: libopenlibm
>
> // T
>
>