If c is a constant, that you want to define in the file test.jl, than you
can define it e.g. at the top of the file
OUTSIDE of the function like this:
const c=2
On Thursday, March 24, 2016 at 5:42:24 AM UTC+1, new to Julia wrote:
>
>
> Thank you so much for your reply. I am still not very clear about what to
> do. Could you explain to me again?
> On Wednesday, March 23, 2016 at 2:48:40 PM UTC-5, Christopher Alexander
> wrote:
>>
>> No, you can call files using "include", but you are only going to
>> import essentially the functions, types, and global variables defined in
>> those files (you should not include a file inside of a function). You do
>> see though how your variable "c" in "test" would not be accessible anywhere
>> else, right?
>>
>> Chris
>>
>> On Wednesday, March 23, 2016 at 3:39:10 PM UTC-4, new to Julia wrote:
>>>
>>> Thanks for your reply. Does it mean that calling files in Julia is
>>> impossible?
>>>
>>> On Wednesday, March 23, 2016 at 1:57:16 PM UTC-5, Christopher Alexander
>>> wrote:
>>>>
>>>> How is test2 supposed to know what "c" is? It is only defined inside
>>>> the scope of the function "test", so it won't be accessible anywhere else.
>>>>
>>>> Chris
>>>>
>>>> On Wednesday, March 23, 2016 at 2:41:29 PM UTC-4, new to Julia wrote:
>>>>>
>>>>> I have a question for calling files in Julia:
>>>>>
>>>>> I have two jl files. And I can call one file from the other file.
>>>>> However, the variable or constant defined in that file cannot be used in
>>>>> the other file. I am wondering that how to fix this? The following is a
>>>>> simple example.
>>>>>
>>>>> function test(x)
>>>>> c=2;
>>>>> y1=6*x;
>>>>> y2=x/5;
>>>>> y1,y2
>>>>> end
>>>>> pwd()
>>>>>
>>>>>
>>>>> ## test and test2 are used for calling functions in Julia
>>>>> function test2(x)
>>>>> include("test.jl")
>>>>> yold,ynew=test(x/c);
>>>>> y3=yold+10;
>>>>> y4=ynew-10;
>>>>> yold2,ynew2=test(x)
>>>>> y5=yold2+20;
>>>>> y6=ynew2-20;
>>>>> y3,y4,y5,y6
>>>>> end
>>>>> y3,y4,y5,y6=test2(100)
>>>>>
>>>>>
>>>>> However, when I run this test2, there is a error comes out: saying
>>>>> that c is not defined.
>>>>>
>>>>> Thank you very much.
>>>>>
>>>>>