You are probably hitting interaction between the scoping rules and include.
This is really not the right way to solve the problem.

On Mon, May 11, 2015 at 10:20 PM, K leo <[email protected]> wrote:

> Thanks for the answer.
>
> I did the following test, which I believe quite resembles my real code,
> and it works:
>
> [/code]
> type Tech
>     cl::Int
>     cm::Int
>
>     function Tech()
>         this = new()
>         this.cl=1
>         this.cm=2
>         this
>     end
> end
>
> 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[/code]
>
> But in my real code,
> [/code]y1 = include_string("tech.cl")[/code]
> doesn't work, complaining that 'tech' is not defined, but
> [/code]y1 = tech.cl[/code]
> in the same place works.
>
> How can I find out what is wrong?
>
> On Tuesday, May 12, 2015, Isaiah Norton <[email protected]> wrote:
>
>> (but, it should be said, that this is a very roundabout way to do things.
>> look at `parse` and `eval`)
>>
>> On Mon, May 11, 2015 at 9:20 PM, Isaiah Norton <[email protected]>
>> wrote:
>>
>>> What is `tech`?
>>>
>>> julia> module tech
>>>        cl = 1
>>>        end
>>>
>>> julia> yy = include_string("tech.cl")
>>> 1
>>>
>>>
>>> On Mon, May 11, 2015 at 8:50 PM, K leo <[email protected]> wrote:
>>>
>>>> Is is broken, or is there something I did wrong?
>>>>
>>>>    _       _ _(_)_     |  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
>>>>
>>>>
>>>> On Sunday, May 10, 2015, K leo <[email protected]> wrote:
>>>>
>>>>> I try read in a variable at run time and use include_string to assign
>>>>> it to another variable, but I got errors.
>>>>>
>>>>> Originally, the following code works:
>>>>>
>>>>>            y1 = tech.cl
>>>>>
>>>>> But when I try to include from input with this code:
>>>>>
>>>>>             println("Input the variable")
>>>>>             tt="\n"
>>>>>             while tt=="\n"
>>>>>                 tt=readline(STDIN)
>>>>>             end
>>>>>             println(tt)
>>>>>             y1 = include_string(tt)
>>>>>
>>>>> then I get the following output and error:
>>>>>
>>>>> Input the variable
>>>>> tech.cl
>>>>> tech.cl
>>>>>
>>>>> ERROR: tech not defined
>>>>>  in include_string at loading.jl:100
>>>>>
>>>>> What is wrong here?
>>>>>
>>>>
>>>
>>

Reply via email to