vscode julia path changed, code to avoid Main.Notebook module context changed
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"julia.environmentPath": "/home/hellmund/Julia/23",
|
||||
"julia.environmentPath": "/home/hellmund/Julia/Book26/JuliaKurs23/",
|
||||
"files.exclude": {
|
||||
"**/.DS_Store": true,
|
||||
"**/.git": true,
|
||||
|
||||
@@ -9,6 +9,7 @@ engine: julia
|
||||
using InteractiveUtils
|
||||
import QuartoNotebookWorker
|
||||
Base.stdout = QuartoNotebookWorker.with_context(stdout)
|
||||
|
||||
```
|
||||
|
||||
# Characters, Strings, and Unicode
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)"
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user