using LinearAlgebra
include(joinpath(@__DIR__, "observations.jl"))
module Station
export score
score(x::Int) = 3x
helper(x) = x + 5
end
module UsingStation
using ..Station
exported_score() = score(7)
missing_helper() = helper(7)
end
module ImportStation
import ..Station
qualified_score() = Station.score(6)
missing_score() = score(6)
end
module ImportScore
import ..Station: score
score(x::Float64) = 3.5x
end
module UsingScore
using ..Station: score
result() = score(8)
end
module LocalGauge
include("gauge-type.jl")
include("gauge-format.jl")
end
probe("module_definition", 4, (Station.score(4),Station.helper(4)), (12,9))
probe("module_using", 7, (UsingStation.exported_score(), outcome(UsingStation.missing_helper)), (21,"UndefVarError"))
probe("module_import", 6, (ImportStation.qualified_score(),outcome(ImportStation.missing_score)), (18,"UndefVarError"))
probe("module_import_name", 2.0, (ImportScore.score(2.0),isdefined(ImportScore,:Station)), (7.0,false))
rejected = outcome(() -> Core.eval(UsingScore, :(score(x::String) = length(x))))
probe("module_using_name", (8,"String extension"), (UsingScore.result(),isdefined(UsingScore,:Station),rejected),
(24,false,"ErrorException"))
probe("module_main", "script top level", (@__MODULE__) === Main, true)
probe("module_base", (3,5), (sum((3,5)),sum === Base.sum), (8,true))
probe("module_core", 4, (Core.typeof(4) === Int,parentmodule(typeof(nothing)) === Core), (true,true))
probe("module_stdlib", [2 5; 1 9], [2 5; 1 9]*I, [2 5; 1 9])
probe("module_include", 19, parentmodule(LocalGauge.Gauge) === LocalGauge, true)
probe("module_show", 19, sprint(show,LocalGauge.Gauge(19)), "Gauge(19 kPa)")
本例需在 Julia 1.10.13 官方便携版,Windows x64,本机隔离目录 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Julia 1.10.13 官方便携版,Windows x64,本机隔离目录
入口文件:projects/julia-modules-tasks/modules.jl
本地运行步骤快速上手
- 点击上方“保存源码”保存为
modules.jl,或下载右侧课程工程包。 - 确认本地已准备 Julia 1.10.13 官方便携版,Windows x64,本机隔离目录。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联24章) · 含当前章节或实例 · mbskycom202612a205.zip
课程关联工程包(登记关联2章) · 含当前章节或实例 · mbskycom202612a212.zip