蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

脚本实例:辨认共享的采样向量

JULIAJulia 1.10.13 官方便携版,Windows x64,本机隔离目录bindings.jl
bindings.jl66 行
module StationTools
struct StationReading
    count::Int
end
ready(record::StationReading) = record.count > 0
macro twice(value)
    return :($(esc(value)) * 2)
end
end

daily_count = 17
δ = 0.025
站点 = "North"
site = "outer"
Site = "inner"
ratio = 2.5
@assert (typeof(daily_count), typeof(站点), typeof(ratio)) == (Int, String, Float64)
@assert δ == 0.025 && site != Site
daily_count = "seventeen"
println("types=", join((typeof(daily_count), typeof(δ), typeof(站点)), ","))

outer = (inner = 9) - 2
west = east = 11
other = outer
outer = 8
@assert (inner, west, east, other, outer) == (9, 11, 11, 7, 8)
println("assign=", join((inner, west, east, other, outer), ","))

readings = [17, 21]
alias = readings
snapshot = copy(readings)
readings[1] = 31
nested = [[12], [19]]
shallow = copy(nested)
independent = deepcopy(nested)
nested[1][1] = 23
@assert alias === readings && snapshot !== readings
@assert shallow[1] === nested[1] && independent[1] !== nested[1]
println("alias=", join((alias[1], snapshot[1], shallow[1][1], independent[1][1]), ","))

record = StationTools.StationReading(37)
scaled = StationTools.@twice 5
@assert record.count == 37 && StationTools.ready(record) && scaled == 10
println("style=", join((record.count, StationTools.ready(record), scaled), ","))

samples = [6, 2]
sorted = sort(samples)
@assert samples == [6, 2] && sorted == [2, 6] && sorted !== samples
@assert sort!(samples) === samples
push!(samples, 9)
println("mutators=", join(samples, ","))

# A single-line comment leaves the expression on the next line intact.
#= Outer comment.
   #= This comment is nested. =#
   End of the outer comment.
=#
println("comments=", 2 + 3)
function is_invalid(source)
    parsed = Meta.parse(source; raise=false)
    return parsed isa Expr && parsed.head == :error
end
invalid = all(word -> is_invalid(word * " = 1"), ["else", "try", "function", "end"])
@assert invalid && is_invalid("/* not a comment */")
println("parse=", invalid)
本例需在 Julia 1.10.13 官方便携版,Windows x64,本机隔离目录 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Julia 1.10.13 官方便携版,Windows x64,本机隔离目录

入口文件:projects/julia-repl-syntax/bindings.jl

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 bindings.jl,或下载右侧课程工程包。
  2. 确认本地已准备 Julia 1.10.13 官方便携版,Windows x64,本机隔离目录。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Julia

课程关联工程包(登记关联2章) · 含当前章节或实例 · mbskycom202612a214.zip

下载课程关联工程包:Julia

课程关联工程包(登记关联24章) · 含当前章节或实例 · mbskycom202612a205.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习