vscode julia path changed, code to avoid Main.Notebook module context changed

This commit is contained in:
2026-03-05 20:50:28 +01:00
parent 733fe8c290
commit 0e6b3d92fa
10 changed files with 90 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
{
"julia.environmentPath": "/home/hellmund/Julia/23",
"julia.environmentPath": "/home/hellmund/Julia/Book26/JuliaKurs23/",
"files.exclude": {
"**/.DS_Store": true,
"**/.git": true,

View File

@@ -9,6 +9,7 @@ engine: julia
using InteractiveUtils
import QuartoNotebookWorker
Base.stdout = QuartoNotebookWorker.with_context(stdout)
```
# Characters, Strings, and Unicode

View File

@@ -7,6 +7,23 @@ engine: julia
#| echo: false
#| output: false
using InteractiveUtils
#struct M a::Int end; x = M(22); @show x
#should not print "Main.Notebook.M(22)" but only "M(22)"
function Base.show(io::IO, x::T) where T
if parentmodule(T) == @__MODULE__
# Print "TypeName(fields...)" without module prefix
print(io, nameof(T), "(")
fields = fieldnames(T)
for (i, f) in enumerate(fields)
print(io, getfield(x, f))
i < length(fields) && print(io, ", ")
end
print(io, ")")
else
invoke(Base.show, Tuple{IO, Any}, io, x)
end
end
```
# Linear Algebra in Julia

View File

@@ -380,6 +380,7 @@ B = readdlm("data2.txt")
In Julia, the `do` notation is frequently utilized for file handling (see @sec-do). The `open()` function includes methods where the first argument is a `function(iostream)`. This function is applied to the stream, which is automatically closed afterward. The `do` notation allows to define this function anonymously:
```{julia}
open("data2.txt", "w") do io
writedlm(io, A)
end
```

View File

@@ -9,10 +9,23 @@ julia:
#| echo: false
#| output: false
using InteractiveUtils
import QuartoNotebookWorker
Base.stdout = QuartoNotebookWorker.with_context(stdout)
myactive_module() = Main.Notebook
Base.active_module() = myactive_module()
#struct M a::Int end; x = M(22); @show x
#should not print "Main.Notebook.M(22)" but only "M(22)"
function Base.show(io::IO, x::T) where T
if parentmodule(T) == @__MODULE__
# Print "TypeName(fields...)" without module prefix
print(io, nameof(T), "(")
fields = fieldnames(T)
for (i, f) in enumerate(fields)
print(io, getfield(x, f))
i < length(fields) && print(io, ", ")
end
print(io, ")")
else
invoke(Base.show, Tuple{IO, Any}, io, x)
end
end
```
# Working with Julia: The REPL, Packages, and Introspection

View File

@@ -7,10 +7,6 @@ engine: julia
#| echo: false
#| output: false
using InteractiveUtils
##import QuartoNotebookWorker
##Base.stdout = QuartoNotebookWorker.with_context(stdout)
##myactive_module() = Main.Notebook
##Base.active_module() = myactive_module()
#struct M a::Int end; x = M(22); @show x
#should not print "Main.Notebook.M(22)" but only "M(22)"

View File

@@ -9,12 +9,23 @@ engine: julia
#| echo: false
#| output: false
using InteractiveUtils
import QuartoNotebookWorker
Base.stdout = QuartoNotebookWorker.with_context(stdout)
myactive_module() = Main.Notebook
Base.active_module() = myactive_module()
# https://github.com/JuliaLang/julia/blob/master/base/show.jl#L516-L520
# https://github.com/JuliaLang/julia/blob/master/base/show.jl#L3073-L3077
#struct M a::Int end; x = M(22); @show x
#should not print "Main.Notebook.M(22)" but only "M(22)"
function Base.show(io::IO, x::T) where T
if parentmodule(T) == @__MODULE__
# Print "TypeName(fields...)" without module prefix
print(io, nameof(T), "(")
fields = fieldnames(T)
for (i, f) in enumerate(fields)
print(io, getfield(x, f))
i < length(fields) && print(io, ", ")
end
print(io, ")")
else
invoke(Base.show, Tuple{IO, Any}, io, x)
end
end
```

View File

@@ -9,10 +9,23 @@ julia:
#| echo: false
#| output: false
using InteractiveUtils
import QuartoNotebookWorker
Base.stdout = QuartoNotebookWorker.with_context(stdout)
myactive_module() = Main.Notebook
Base.active_module() = myactive_module()
#struct M a::Int end; x = M(22); @show x
#should not print "Main.Notebook.M(22)" but only "M(22)"
function Base.show(io::IO, x::T) where T
if parentmodule(T) == @__MODULE__
# Print "TypeName(fields...)" without module prefix
print(io, nameof(T), "(")
fields = fieldnames(T)
for (i, f) in enumerate(fields)
print(io, getfield(x, f))
i < length(fields) && print(io, ", ")
end
print(io, ")")
else
invoke(Base.show, Tuple{IO, Any}, io, x)
end
end
```
# Machine Numbers

View File

@@ -10,6 +10,8 @@ engine: julia
#| output: false
using InteractiveUtils
#struct M a::Int end; x = M(22); @show x
#should not print "Main.Notebook.M(22)" but only "M(22)"
function Base.show(io::IO, x::T) where T
if parentmodule(T) == @__MODULE__
# Print "TypeName(fields...)" without module prefix
@@ -24,14 +26,6 @@ function Base.show(io::IO, x::T) where T
invoke(Base.show, Tuple{IO, Any}, io, x)
end
end
##import QuartoNotebookWorker
##Base.stdout = QuartoNotebookWorker.with_context(stdout)
##myactive_module() = Main.Notebook
##Base.active_module() = myactive_module()
# https://github.com/JuliaLang/julia/blob/master/base/show.jl#L516-L520
# https://github.com/JuliaLang/julia/blob/master/base/show.jl#L3073-L3077
```

View File

@@ -8,10 +8,23 @@ engine: julia
#| echo: false
#| output: false
using InteractiveUtils
import QuartoNotebookWorker
Base.stdout = QuartoNotebookWorker.with_context(stdout)
myactive_module() = Main.Notebook
Base.active_module() = myactive_module()
#struct M a::Int end; x = M(22); @show x
#should not print "Main.Notebook.M(22)" but only "M(22)"
function Base.show(io::IO, x::T) where T
if parentmodule(T) == @__MODULE__
# Print "TypeName(fields...)" without module prefix
print(io, nameof(T), "(")
fields = fieldnames(T)
for (i, f) in enumerate(fields)
print(io, getfield(x, f))
i < length(fields) && print(io, ", ")
end
print(io, ")")
else
invoke(Base.show, Tuple{IO, Any}, io, x)
end
end
```