# @from (from Fromfile) does not work inside begin-en for local module workflow

**URL:** <https://discourse.julialang.org/t/from-from-fromfile-does-not-work-inside-begin-en-for-local-module-workflow/76100>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [February 9, 2022, 4:15pm UTC](https://discourse.julialang.org/t/from-from-fromfile-does-not-work-inside-begin-en-for-local-module-workflow/76100 "2022-02-09T16:15:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)\
**Post date:** [February 9, 2022, 4:15pm UTC](https://discourse.julialang.org/t/from-from-fromfile-does-not-work-inside-begin-en-for-local-module-workflow/76100/1 "2022-02-09T16:15:10Z")

</div>

I have been trying to get my “local modules” workflow from previous {either include or push loadpath} to using excellent @Roger-luo `FromFile`. But the case I was using it get me trouble, specifically it fails when included inside `begin ...end`

For an MWE : I have following file `tmod.jl`

```julia
module tmod
function hello()
    println("hello from tmod")
end
function __init__ ()
    hello()
end
end

```

If, in REPL, doing

```julia
using FromFile
@from "tmod.jl" using tmod

```

it works, if doing

```julia
begin
using FromFile
@from "tmod.jl" using tmod
end

```

I get

```julia
ERROR: LoadError: UndefVarError: @from not defined
in expression starting at REPL[1]:3

```

Why is that ?  
For the record, the two others way of doing it

```julia
if !@isdefined tmod; include("tmod.jl"); using .tmod; end

```

and

```julia
pushfirst!(LOAD_PATH,@ __DIR__ )
using tmod
popfirst!(LOAD_PATH)

```

when used inside begin/end do not suffer with the same trouble.  
So, why is that the `@from` does not work when is same block as `using FromFile`?

Notes

- Include solution seems a bit “tormented” for me, and puts the module in the Main namespace while the two other ones put it in the Global namespace IIUC.

- LOAD\_PATH manipulation makes me fears that it is not really “Julia-esque” and may be could fail for later Julia versions - may be I should not worry ? Also, will vs-code referencing work with this way of doing things ? (because of the pop of loadpath makes it loose the path to the module?)

- This is an aside question but not some kind of XY problem, I was trying to get timing info for my "using"s, by way of TimerOutputs, so put those usings in a begin/end block for that. Then it failed ! I know I can can put the `using FromFile`at the beginning of the file and then it should work, but I would like to understand why when this using and the`@from` are in the same block, it does not work.

Thanks for comment about my question, and possibly, also, more generally, about best/better local module workflow)

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [February 10, 2022, 3:36am UTC](https://discourse.julialang.org/t/from-from-fromfile-does-not-work-inside-begin-en-for-local-module-workflow/76100/2 "2022-02-10T03:36:51Z")

</div>

hmm…this does not seems to be a `FromFile` issue, but a Julia issue

```julia
julia> begin
       using LinearAlgebra
       LinearAlgebra.@commutative
       end
ERROR: LoadError: UndefVarError: LinearAlgebra not defined
in expression starting at REPL[1]:3

```

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [February 10, 2022, 3:42am UTC](https://discourse.julialang.org/t/from-from-fromfile-does-not-work-inside-begin-en-for-local-module-workflow/76100/3 "2022-02-10T03:42:56Z")

</div>

I created an issue here: [https://github.com/JuliaLang/julia/issues/44104](https://github.com/JuliaLang/julia/issues/44104)

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [February 11, 2022, 12:33am UTC](https://discourse.julialang.org/t/from-from-fromfile-does-not-work-inside-begin-en-for-local-module-workflow/76100/4 "2022-02-11T00:33:46Z")

</div>

as pointed out in the issue

> Those two aren’t equivalent. Macro expansion will always happen on the whole top-level expression before any code is evaluated.

so this is the limitation of FromFile we will need a proper implementation within the loading  
to have the behavior properly, which is unlikely to happen any time soon. Unless someone can convince the rest of the community about it.

I assume you are using Pluto which cause you hit this? I’m not sure if @fonsp has any idea of a workaround in Pluto, perhaps no.

---

<div class="post-metadata">

**Author:** ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)\
**Post date:** [February 11, 2022, 7:58am UTC](https://discourse.julialang.org/t/from-from-fromfile-does-not-work-inside-begin-en-for-local-module-workflow/76100/5 "2022-02-11T07:58:14Z")

</div>

Thanks for your effort. I understand that the question here is a general issue with macro parsing, not specific to FromFile. So I will keep that in mind (I have learn something!) for later.

Regarding your question, no I am not using Pluto for this specific case. But I agree that it could be, as Pluto is a wonderful product! And so your yours. Cheers!
