Reading matrices from an external file inside a function

If “such a file” is a normal julia source code and reading into local scope meaning create local variables depending on the variables defined in the file then no it’s impossible and won’t be possible.

No. That’s not what that link says. That link says that you could create a macro so that it’s as if you just included the content of A.jl in at compile time, i.e. when you define the function f. You will not read in a different value when you run f and can’t pass in the file name at runtime (as a parameter to the function).

Now you should treat your input file like any other data file and what you need is just a way to read in a file containing data. If you do this then yes there are many different ways to do what you want. I highly doubt your requirement contains being able to support full julia syntax so you likely don’t need to use a full julia script to store your data. You shouuld identify your actual requirements to help yourself and others to decide which format is the best fit for you.

It is also possible if you need to support full julia syntax. However, that means you are throwing anything remotely related to sercurity out of the door and is getting rid of any gard from any user mistake (let along users with ill-intent).

1 Like