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": {
|
"files.exclude": {
|
||||||
"**/.DS_Store": true,
|
"**/.DS_Store": true,
|
||||||
"**/.git": true,
|
"**/.git": true,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ engine: julia
|
|||||||
using InteractiveUtils
|
using InteractiveUtils
|
||||||
import QuartoNotebookWorker
|
import QuartoNotebookWorker
|
||||||
Base.stdout = QuartoNotebookWorker.with_context(stdout)
|
Base.stdout = QuartoNotebookWorker.with_context(stdout)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# Characters, Strings, and Unicode
|
# Characters, Strings, and Unicode
|
||||||
|
|||||||
@@ -7,6 +7,23 @@ engine: julia
|
|||||||
#| echo: false
|
#| echo: false
|
||||||
#| output: false
|
#| output: false
|
||||||
using InteractiveUtils
|
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
|
# 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:
|
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}
|
```{julia}
|
||||||
|
open("data2.txt", "w") do io
|
||||||
writedlm(io, A)
|
writedlm(io, A)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -9,10 +9,23 @@ julia:
|
|||||||
#| echo: false
|
#| echo: false
|
||||||
#| output: false
|
#| output: false
|
||||||
using InteractiveUtils
|
using InteractiveUtils
|
||||||
import QuartoNotebookWorker
|
|
||||||
Base.stdout = QuartoNotebookWorker.with_context(stdout)
|
#struct M a::Int end; x = M(22); @show x
|
||||||
myactive_module() = Main.Notebook
|
#should not print "Main.Notebook.M(22)" but only "M(22)"
|
||||||
Base.active_module() = myactive_module()
|
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
|
# Working with Julia: The REPL, Packages, and Introspection
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ engine: julia
|
|||||||
#| echo: false
|
#| echo: false
|
||||||
#| output: false
|
#| output: false
|
||||||
using InteractiveUtils
|
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
|
#struct M a::Int end; x = M(22); @show x
|
||||||
#should not print "Main.Notebook.M(22)" but only "M(22)"
|
#should not print "Main.Notebook.M(22)" but only "M(22)"
|
||||||
|
|||||||
@@ -9,12 +9,23 @@ engine: julia
|
|||||||
#| echo: false
|
#| echo: false
|
||||||
#| output: false
|
#| output: false
|
||||||
using InteractiveUtils
|
using InteractiveUtils
|
||||||
import QuartoNotebookWorker
|
|
||||||
Base.stdout = QuartoNotebookWorker.with_context(stdout)
|
#struct M a::Int end; x = M(22); @show x
|
||||||
myactive_module() = Main.Notebook
|
#should not print "Main.Notebook.M(22)" but only "M(22)"
|
||||||
Base.active_module() = myactive_module()
|
function Base.show(io::IO, x::T) where T
|
||||||
# https://github.com/JuliaLang/julia/blob/master/base/show.jl#L516-L520
|
if parentmodule(T) == @__MODULE__
|
||||||
# https://github.com/JuliaLang/julia/blob/master/base/show.jl#L3073-L3077
|
# 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
|
#| echo: false
|
||||||
#| output: false
|
#| output: false
|
||||||
using InteractiveUtils
|
using InteractiveUtils
|
||||||
import QuartoNotebookWorker
|
|
||||||
Base.stdout = QuartoNotebookWorker.with_context(stdout)
|
#struct M a::Int end; x = M(22); @show x
|
||||||
myactive_module() = Main.Notebook
|
#should not print "Main.Notebook.M(22)" but only "M(22)"
|
||||||
Base.active_module() = myactive_module()
|
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
|
# Machine Numbers
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ engine: julia
|
|||||||
#| output: false
|
#| output: false
|
||||||
using InteractiveUtils
|
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
|
function Base.show(io::IO, x::T) where T
|
||||||
if parentmodule(T) == @__MODULE__
|
if parentmodule(T) == @__MODULE__
|
||||||
# Print "TypeName(fields...)" without module prefix
|
# 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)
|
invoke(Base.show, Tuple{IO, Any}, io, x)
|
||||||
end
|
end
|
||||||
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
|
#| echo: false
|
||||||
#| output: false
|
#| output: false
|
||||||
using InteractiveUtils
|
using InteractiveUtils
|
||||||
import QuartoNotebookWorker
|
|
||||||
Base.stdout = QuartoNotebookWorker.with_context(stdout)
|
#struct M a::Int end; x = M(22); @show x
|
||||||
myactive_module() = Main.Notebook
|
#should not print "Main.Notebook.M(22)" but only "M(22)"
|
||||||
Base.active_module() = myactive_module()
|
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