As I understand it include_string() uses eval() to evaluate the string, and 
eval() operates at module level according 
to http://docs.julialang.org/en/latest/stdlib/base/?highlight=eval#Base.eval 
so it won't see a function local variable.

On Tuesday, May 12, 2015 at 12:34:13 PM UTC+10, K leo wrote:
>
> I guess I found the problem, but don't know a solution.
>
> The following test code (same as the previous one except that I put them 
> in a function) now produces the same problem as my real code.
>
> type Tech
>     cl::Array{Float64,1}
>     cm::Array{Float64,1}
>
>     function Tech()
>         this = new() 
>         this.cl=[1:4]
>         this.cm=[6:10]
>         this
>     end
> end
>
> function mytest()
>     tech = Tech()
>     while true
>         println("input a choice")
>         ch = read(STDIN, Char)
>         if ch=='l'
>             y1 = include_string("tech.cl")
>             println(y1)
>         elseif ch=='m'
>             y1 = include_string("tech.cm")
>             println(y1)
>     elseif ch=='q'
>                 break
>         end
>     end
> end
> ---------------------------------
>
>    _       _ _(_)_     |  A fresh approach to technical computing
>   (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
>    _ _   _| |_  __ _   |  Type "help()" for help.
>   | | | | | | |/ _` |  |
>   | | |_| | | | (_| |  |  Version 0.3.8 (2015-04-30 23:40 UTC)
>  _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org release
> |__/                   |  x86_64-linux-gnu
>
> julia> include("test.jl")
> mytest (generic function with 1 method)
>
> julia> mytest()
> input a choice
> l
> ERROR: tech not defined
>  in mytest at /home/xxxx/Coding/Julia/test.jl:19
> while loading string, in expression starting on line 1
>
>
>
>

Reply via email to