Pluto.jl icon indicating copy to clipboard operation
Pluto.jl copied to clipboard

let block scoping differs from standalone script

Open fonsp opened this issue 1 year ago • 0 comments

Discussed in https://github.com/fonsp/Pluto.jl/discussions/2592

Originally posted by jonas-schulze July 3, 2023 When working with DataFrames, I like to wrap more complex cells in a let ... end block and reuse the name df. However, when executing such notebooks as a script, Julia complains about df being not defined. Why is Pluto interpreting the code differently than plain Julia does? I tried to argue that this is a bug within Julia, see https://github.com/JuliaLang/julia/issues/50369, but some developers seemed to disagree. What's your take on this, @fonsp?

### A Pluto.jl notebook ###
# v0.19.14

using Markdown
using InteractiveUtils

# ╔═╡ 397dbe3c-05ef-4f9f-87df-3230dd816d56
x = 5

# ╔═╡ 7d0149a1-c675-449f-8348-87c1f7d98935
y = let
	x = 2x
	x += 1
end

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
"""

# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised

julia_version = "1.8.5"
manifest_format = "2.0"
project_hash = "da39a3ee5e6b4b0d3255bfef95601890afd80709"

[deps]
"""

# ╔═╡ Cell order:
# ╠═397dbe3c-05ef-4f9f-87df-3230dd816d56
# ╠═7d0149a1-c675-449f-8348-87c1f7d98935
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002
$ julia pluto-undef-var.jl 
ERROR: LoadError: UndefVarError: x not defined
Stacktrace:
 [1] top-level scope
   @ ~/tmp/pluto-undef-var.jl:12
in expression starting at /home/jschulze/tmp/pluto-undef-var.jl:11
```</div>

fonsp avatar Jul 08 '23 09:07 fonsp