wip(0.S1, 0.S2): state records, mut and read-only state parameters, entry injection, module var refused; ludic migrate state
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
63a1fa1378
commit
1e8b5b0523
35 changed files with 1227 additions and 30 deletions
8
examples/rejected/module_let_write.ludic
Normal file
8
examples/rejected/module_let_write.ludic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# 0.S: a module-level let is immutable all the way down - a write through it is refused
|
||||
program ModuleLetWrite {
|
||||
let LIMITS: []int = [1, 2]
|
||||
entry {
|
||||
LIMITS[0] = 3
|
||||
print(LIMITS[0])
|
||||
}
|
||||
}
|
||||
7
examples/rejected/module_var.ludic
Normal file
7
examples/rejected/module_var.ludic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# 0.S: a module-level var is refused - a module's changing data is its state
|
||||
program ModuleVar {
|
||||
var count: int = 0
|
||||
entry {
|
||||
print(count)
|
||||
}
|
||||
}
|
||||
7
examples/rejected/mut_not_state.ludic
Normal file
7
examples/rejected/mut_not_state.ludic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# 0.S: `mut` is for a state parameter
|
||||
program MutNotState {
|
||||
function f(x: mut int) -> int { return x }
|
||||
entry {
|
||||
print(f(1))
|
||||
}
|
||||
}
|
||||
9
examples/rejected/state_mut_arg.ludic
Normal file
9
examples/rejected/state_mut_arg.ludic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# 0.S: a read-only state is not handed on where a mut one is wanted
|
||||
program StateMutArg {
|
||||
state Tally { n: int = 0 }
|
||||
function bump(c: mut Tally) -> void { c.n += 1 }
|
||||
function look(c: Tally) -> void { bump(c) }
|
||||
entry (c: Tally) {
|
||||
look(c)
|
||||
}
|
||||
}
|
||||
11
examples/rejected/state_readonly.ludic
Normal file
11
examples/rejected/state_readonly.ludic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# 0.S: a state taken without `mut` is read-only - assigning through it is refused
|
||||
program StateReadonly {
|
||||
state Tally { n: int = 0 }
|
||||
function peek(c: Tally) -> int {
|
||||
c.n = 1
|
||||
return c.n
|
||||
}
|
||||
entry (c: Tally) {
|
||||
print(peek(c))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue