fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia
https://plutojl.org/
MIT License
4.96k stars 286 forks source link

Hidden definitions from macro defined inside notebook #2486

Open fonsp opened 1 year ago

fonsp commented 1 year ago

When you run the following notebook:

# ╔═╡ 7659d0cc-b872-11ed-2e70-d767b8913f62
begin
    sleep(3)
    x
end

# ╔═╡ 820a8851-0a89-417b-b795-b2d1b67d9680
begin
    sleep(3)
    @asdf x
end

# ╔═╡ 18263a21-e163-4330-96cd-b17f37ccd033
macro asdf(name::Symbol)
    :($(esc(name)) = rand())
end

The first cell initially errors, because it runs before the other cells:

image

When you run the cell a second time, it shows the correct result.

Pangoraw commented 1 year ago

We don't rerun cells from the same reactive run on macro resolution:

https://github.com/fonsp/Pluto.jl/blob/776cbf7cb37770dbc60bc037737ed143a1fa0f58/src/evaluation/Run.jl#L118

This problem does not happen with reactive using Package because cells with using have a higher precedence heuristic than other cells.