# Some questions on \`startup.jl\`

**URL:** https://discourse.julialang.org/t/some-questions-on-startup-jl/99752
**Category:** General Usage
**Tags:** question
**Created:** [June 2, 2023, 4:00am UTC](https://discourse.julialang.org/t/some-questions-on-startup-jl/99752 "2023-06-02T04:00:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)
#### Post date: [June 2, 2023, 4:00am UTC](https://discourse.julialang.org/t/some-questions-on-startup-jl/99752/1 "2023-06-02T04:00:35Z")

</div>

I am configuring the automatic start of `OhMyREPL.jl`. The [document](https://docs.juliahub.com/OhMyREPL/08e1i/0.5.22/installation/) advise putting the following code in the `.julia/config/startup.jl` file:

```julia
atreplinit() do repl
    try
        @eval using OhMyREPL
        println("OhMyREPL imported") # I add this line
    catch e
        @warn "error while importing OhMyREPL" e
    end
end

```

Now I have some questions on this code:

1. Why do I have to write the `try...catch...end` code segment into the `atreplinit() do repl...end`?
2. Why do I have to add an `@eval` before `using OhMyREPL` but unnecessarily do that before `println(“OhMyREPL imported”)`?

---

<div class="post-metadata">

### Author: ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)
#### Post date: [June 2, 2023, 6:07am UTC](https://discourse.julialang.org/t/some-questions-on-startup-jl/99752/2 "2023-06-02T06:07:20Z")

</div>

1. Because it can fail, e.g. if the package is not actually installed.
2. Because all the code between `do ... end` is an anonymous function, and [it is not possible to import modules in a function’s scope](https://discourse.julialang.org/t/why-wont-julia-let-me-put-a-module-import-within-a-function/46504/4). So this is one of those rare cases where it makes sense to use `@eval` inside a function, so that the instruction is executed in the outer scope.

---

<div class="post-metadata">

### Author: ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)
#### Post date: [June 2, 2023, 9:13am UTC](https://discourse.julialang.org/t/some-questions-on-startup-jl/99752/3 "2023-06-02T09:13:11Z")

</div>

Thanks for response!

In my first question I actually want to know why is the `atreplinit() do repl ... end` block necessary?

---

<div class="post-metadata">

### Author: ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)
#### Post date: [June 2, 2023, 9:19am UTC](https://discourse.julialang.org/t/some-questions-on-startup-jl/99752/4 "2023-06-02T09:19:50Z")

</div>

From the docs

```julia
help?> atreplinit
search: atreplinit

  atreplinit(f)

  Register a one-argument function to be called before the REPL interface is initialized in interactive sessions; this is useful to customize the interface. The
  argument of f is the REPL object. This function should be called from within the .julia/config/startup.jl initialization file.

```

It is added so that `OhMyREPL` is only loaded when running interactively.  
If you are using Julia just to run a script once, like `julia compute_something.jl`, then you likely don’t need `OhMyREPL`, so the above prevents that.
