I have a julia file that contains functions and code that uses those functions. I would like to create a separate julia script that is able to execute this script (and obtain one of the values that is created at the end of the script).
However, I would like the separate julia script to be able to pass a parameter to the first script when calling it. I can’t figure out how to do this part. I’m a beginner to julia, so I’d appreciate an answer in simple terms!
Is a command-line parameter that you are talking about? Julia has ARGS that is a global vector with the command-line parameters as Strings. You can change the first script to check the arguments there, and then call it from the second script as you can do with any script (with run).
In Julia, calling the script from another script is not at all a common practice.
Here is how you can achieve the desired behavior:
Content of script to be called (let’s name it script-a.jl):
function fwithparam(x)
x + 1
end
Caller content (let’s say script-b.jl):
include("script-a.jl") # assuming it is in the same directory
# now - you have access to your fwithparam function
println(fwithparam(10)) # should print 11
Because the interface may only be defined at script level? If you include and in the future you change the name of the functions, or how you do the things, or the language of the script then the including script will break. Other reason is that if you start using include in a frequent manner, you will start having problems with script C includes script B and A, and script B includes script A too, but then you have double included A and things may start to get in disarray.
It’s not clear what your goals and motivations are. I suppose you could put the functions into a single file, perhaps organized into a module, and then include this from other .jl files, as ufechner7 wrote.
@clairem, I see that you picked one of my posts as the solution - however, I think you wanted to pick the other one where I answered specifically to your original question.
I am only writing this to make it easier for other users with similar questions that might stumble upon this thread.