# Inspect a Julia source code from an other Julia code

**URL:** <https://discourse.julialang.org/t/inspect-a-julia-source-code-from-an-other-julia-code/101547>\
**Category:** General Usage\
**Created:** [July 12, 2023, 6:32pm UTC](https://discourse.julialang.org/t/inspect-a-julia-source-code-from-an-other-julia-code/101547 "2023-07-12T18:32:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FemtoTrader](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/femtotrader/32/309_2.png) [@FemtoTrader](https://discourse.julialang.org/u/FemtoTrader)\
**Post date:** [July 12, 2023, 6:32pm UTC](https://discourse.julialang.org/t/inspect-a-julia-source-code-from-an-other-julia-code/101547/1 "2023-07-12T18:32:53Z")

</div>

Hello,

I’m looking for a way to “inspect” a Julia source code from an other Julia code ie I would like to ensure that a code which is stored in a `strat.jl` file contains an `init` function from an Julia code named `runner.jl`.

I did  
`runner.jl`

```julia
using ArgParse

function backtest(strategy)
    @info "Running '$strategy'"
    include(strategy)
    initialize(nothing)
end

function parse_commandline()
    s = ArgParseSettings()

    @add_arg_table! s begin
        "--opt1"
            help = "an option with an argument"
        "--opt2", "-o"
            help = "another option with an argument"
            arg_type = Int
            default = 0
        "--flag1"
            help = "an option without argument, i.e. a flag"
            action = :store_true
        "action"
            help = "action (download, backtest, ...)"
            required = true
        "strategy"
            help = "filename of a strategy"
            required = true
    end

    return parse_args(s)
end

function main()
    @info "begin of runner"
    parsed_args = parse_commandline()
    @info "Parsed args:"
    for (arg, val) in parsed_args
         @info " $arg => $val"
    end
    if parsed_args["action"] == "backtest"
        backtest(parsed_args["strategy"])
    end
    @info "end of runner"
end

main()

```

and `strat.jl`

```julia
function initialize(state)
    println("strat init")
end

function handler1(state, data)
    println("handler1")
end

```

but it raises an error that I’ve never seen before…

`The applicable method may be too new: running in world age 33497, while current world is 33499.`

Code should be run like this

```julia
julia runner.jl backtest strat.jl

```

Any idea how to tackle that ? Sorry if that’s trivial I haven’t looked at Julia recently.

Thanks

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/224680_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 12, 2023, 6:55pm UTC](https://discourse.julialang.org/t/inspect-a-julia-source-code-from-an-other-julia-code/101547/2 "2023-07-12T18:55:44Z")

</div>

> [@FemtoTrader](#):
>
> I’m looking for a way to “inspect” a Julia source code from an other Julia code ie I would like to ensure that a code which is stored in a `strat.jl` file contains an `init` function from an Julia code named `runner.jl`.

Can you explain why you want to do that? It sounds way too convoluted, which makes me suspect an [XY problem](https://en.wikipedia.org/wiki/XY_problem)

---

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [July 12, 2023, 7:02pm UTC](https://discourse.julialang.org/t/inspect-a-julia-source-code-from-an-other-julia-code/101547/3 "2023-07-12T19:02:04Z")

</div>

I think @gdalle has a good point.

Just to clarify what’s going on though: this is a “world-age issue” which (to my understanding) happens when you define a function that should live in the scope of `Main`, but you defined it within another function. When you now try to call the newly defined function before you are back to `Main`s scope, you get a world-age error.

There is some more detailed discussion [here](https://discourse.julialang.org/t/world-age-problem-explanation/9714/3) and a StackOverflow answer [here](https://stackoverflow.com/a/41288817) which shows the behavior of `include`.

---

<div class="post-metadata">

**Author:** ![FemtoTrader](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/femtotrader/32/309_2.png) [@FemtoTrader](https://discourse.julialang.org/u/FemtoTrader)\
**Post date:** [July 12, 2023, 7:13pm UTC](https://discourse.julialang.org/t/inspect-a-julia-source-code-from-an-other-julia-code/101547/4 "2023-07-12T19:13:19Z")

</div>

I want to have only one entrypoint for running a strategy (a trading program).  
This entrypoint will be `runner.jl`. I want to be able to pass to runner (using command line) the filename of a strategy I want to execute. To achieve this, a strategy have some “requirements”. It must have an `initialize` function and at least one `handler`  
The runner will be responsible of giving to the strategy all the context required to be executed. So I can’t for example directly run `julia strat.jl` because the strategy itself can’t do anything without the “context”.  
I hope it’s clearer.  
This is how work for example Python backtester named zipline

> **[GitHub - quantopian/zipline: Zipline, a Pythonic Algorithmic Trading Library](https://github.com/quantopian/zipline)**
>
> Zipline, a Pythonic Algorithmic Trading Library. Contribute to quantopian/zipline development by creating an account on GitHub.

```
zipline run -f dual_moving_average.py --start 2014-1-1 --end 2018-1-1 -o dma.pickle --no-benchmark

```

zipline is a Python program which run dual\_moving\_average.py (strategy) with some context information (start date and end date of backtest)

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/224680_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 12, 2023, 7:19pm UTC](https://discourse.julialang.org/t/inspect-a-julia-source-code-from-an-other-julia-code/101547/5 "2023-07-12T19:19:47Z")

</div>

To me it sounds like a strategy should be a Julia type instead of a file, with several methods designed to dispatch on that type and give it information from the runner.

What you’re trying to specify / check is an interface, and while there is no standard way to do that in Julia, there are several promising (but recent, and thus possibly buggy) attempts:

- [GitHub - Seelengrab/RequiredInterfaces.jl: A small package for providing the minimal required method surface of a Julia API](https://github.com/Seelengrab/RequiredInterfaces.jl)
- [GitHub - rafaqz/Interfaces.jl: Macros to define and implement interfaces, to ensure they are checked and correct.](https://github.com/rafaqz/Interfaces.jl)
