常數
const app_version = '1.0.0'const (
app_version = '1.0.0'
max_size = 1024
)struct Point {
mut:
x f32
y f32
z f32
}
const origin = Point {
x: 0.0
y: 0.0,
z: 0.0
}Last updated
const app_version = '1.0.0'const (
app_version = '1.0.0'
max_size = 1024
)struct Point {
mut:
x f32
y f32
z f32
}
const origin = Point {
x: 0.0
y: 0.0,
z: 0.0
}Last updated
module main
struct Point {
mut:
x f32
y f32
z f32
}
fn shift_y(p Point, offset f32) Point {
return Point{
x: p.x
y: p.y + offset
z: p.z
}
}
const (
origin = Point{
x: 0.0
y: 0.0
z: 0.0
}
origin_y = shift_y(origin, 2.5)
)
fn main() {
print(origin_y)
}module main
fn main() {
const app_version = '1.0.0'
// error: const can only be defined at the top level (outside of functions)
print(app_version)
}module bar
const foo = 1
pub fn run() {
print(bar.foo)
}