wip(0.S3): packages and examples migrated in one run - ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d490d4f9f1
commit
3eda72e8c2
172 changed files with 3094 additions and 2966 deletions
|
|
@ -1,13 +1,15 @@
|
|||
# bank/ledger.ludic - inherits `module bank` from the barrel that imports it
|
||||
var balance: int = 0
|
||||
export event Deposited { amount: int }
|
||||
function add(n: int) -> void {
|
||||
balance += n
|
||||
export state BankState {
|
||||
balance: int = 0
|
||||
}
|
||||
export function deposit(n: int) -> void {
|
||||
add(n)
|
||||
export event Deposited { amount: int }
|
||||
function add(bank_st: mut BankState, n: int) -> void {
|
||||
bank_st.balance += n
|
||||
}
|
||||
export function deposit(bank_st: mut BankState, n: int) -> void {
|
||||
add(bank_st, n)
|
||||
emit Deposited(amount: n)
|
||||
}
|
||||
export function total() -> int {
|
||||
return balance
|
||||
export function total(bank_st: BankState) -> int {
|
||||
return bank_st.balance
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
import "bank"
|
||||
program FriendOf {
|
||||
friend module lab of bank
|
||||
entry {
|
||||
add(7)
|
||||
print(`{balance} {total()}`)
|
||||
entry (bank_st: mut BankState) {
|
||||
add(bank_st, 7)
|
||||
print(`{bank_st.balance} {total(bank_st)}`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,19 @@ property Catch {
|
|||
fish: int = 0
|
||||
}
|
||||
event Landed { fish: int }
|
||||
var landed: int = 0
|
||||
var last: Catch = null
|
||||
@On(Landed) handler Count { landed += fish }
|
||||
export state FishingState {
|
||||
landed: int = 0
|
||||
last: Catch = null
|
||||
}
|
||||
@On(Landed) handler Count(fishing_st: mut FishingState) { fishing_st.landed += fish }
|
||||
function catch_new(n: int) -> Catch {
|
||||
let c = new Catch
|
||||
c.fish = n
|
||||
return c
|
||||
}
|
||||
export function fishing_day() -> int {
|
||||
last = catch_new(3)
|
||||
emit Landed(fish: last.fish)
|
||||
export function fishing_day(fishing_st: mut FishingState) -> int {
|
||||
fishing_st.last = catch_new(3)
|
||||
emit Landed(fish: fishing_st.last.fish)
|
||||
emit Landed(fish: 4)
|
||||
return landed
|
||||
return fishing_st.landed
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@ property Catch {
|
|||
weight: float = 0.0
|
||||
}
|
||||
event Landed { name: string }
|
||||
var heard: string = ""
|
||||
@On(Landed) handler Hear { heard = heard + name }
|
||||
export function hunting_day() -> string {
|
||||
export state HuntingState {
|
||||
heard: string = ""
|
||||
}
|
||||
@On(Landed) handler Hear(hunting_st: mut HuntingState) { hunting_st.heard = hunting_st.heard + name }
|
||||
export function hunting_day(hunting_st: HuntingState) -> string {
|
||||
let c = new Catch
|
||||
c.name = "hare"
|
||||
emit Landed(name: c.name)
|
||||
return heard
|
||||
return hunting_st.heard
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,15 +8,17 @@ program PortVars {
|
|||
money: fn() -> int
|
||||
price: fn(int) -> int
|
||||
}
|
||||
var g_money: int = 40
|
||||
var g_rate: int = 3
|
||||
function priced(n: int) -> int {
|
||||
return n * g_rate
|
||||
state PortvarsState {
|
||||
g_money: int = 40
|
||||
g_rate: int = 3
|
||||
}
|
||||
bind Purse { money: g_money, price: fn priced }
|
||||
entry {
|
||||
function priced(portvars_st: PortvarsState, n: int) -> int {
|
||||
return n * portvars_st.g_rate
|
||||
}
|
||||
bind Purse { money: PortvarsState.g_money, price: fn priced }
|
||||
entry (portvars_st: mut PortvarsState) {
|
||||
let a = Purse.money()
|
||||
g_money += 5
|
||||
portvars_st.g_money += 5
|
||||
print(`{a} {Purse.money()} {Purse.price(4)}`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import "station/units"
|
|||
import "station/clock"
|
||||
import "station/app"
|
||||
program Ports {
|
||||
entry {
|
||||
entry (app_st: mut AppState) {
|
||||
let a = Clock.now()
|
||||
advance(-25)
|
||||
advance(app_st, -25)
|
||||
print(`{a} {hour_of_day()}`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
import "kinds/fishing"
|
||||
import "kinds/hunting"
|
||||
program PrivateKinds {
|
||||
entry {
|
||||
print(`{fishing_day()} {hunting_day()}`)
|
||||
entry (fishing_st: mut FishingState, hunting_st: HuntingState) {
|
||||
print(`{fishing_day(fishing_st)} {hunting_day(hunting_st)}`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ program PrivateTwins {
|
|||
function seed() -> int {
|
||||
return 7
|
||||
}
|
||||
entry {
|
||||
print(`{shop_seed()} {weather_seed()} {seed()}`)
|
||||
entry (shop_st: ShopState, weather_st: WeatherState) {
|
||||
print(`{shop_seed(shop_st)} {weather_seed(weather_st)} {seed()}`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
# app/index.ludic - the app puts the program together: it sees the port and fills it
|
||||
module app uses clock
|
||||
bind Clock { now: fn game_hours }
|
||||
var g_hours: int = 30
|
||||
function game_hours() -> int {
|
||||
return g_hours
|
||||
export state AppState {
|
||||
g_hours: int = 30
|
||||
}
|
||||
export function advance(h: int) -> void {
|
||||
g_hours += h
|
||||
function game_hours(app_st: AppState) -> int {
|
||||
return app_st.g_hours
|
||||
}
|
||||
export function advance(app_st: mut AppState, h: int) -> void {
|
||||
app_st.g_hours += h
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import "tangle/c"
|
|||
import "tangle/a"
|
||||
import "tangle/b"
|
||||
program Tangle {
|
||||
entry {
|
||||
a_bump()
|
||||
print(a_run() + b_rec.n - 1)
|
||||
entry (b_st: mut BState) {
|
||||
a_bump(b_st)
|
||||
print(a_run(b_st) + b_st.b_rec.n - 1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
# a/index.ludic - uses b, and writes b's global from outside it
|
||||
module a
|
||||
export function a_run() -> int {
|
||||
b_count = b_count + 1
|
||||
export function a_run(b_st: mut BState) -> int {
|
||||
b_st.b_count = b_st.b_count + 1
|
||||
return b_run() + c_one()
|
||||
}
|
||||
export function a_two() -> int {
|
||||
return 2
|
||||
}
|
||||
export function a_bump() -> void {
|
||||
let r = b_rec
|
||||
export function a_bump(b_st: mut BState) -> void {
|
||||
let r = b_st.b_rec
|
||||
r.n = r.n + 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
# b/index.ludic - uses a back: a and b are a cycle
|
||||
module b
|
||||
export var b_count: int = 0
|
||||
export state BState {
|
||||
b_count: int = 0
|
||||
b_rec: Tally = new Tally
|
||||
}
|
||||
export property Tally {
|
||||
n: int = 0
|
||||
}
|
||||
export var b_rec: Tally = new Tally
|
||||
export function b_run() -> int {
|
||||
return a_two() + c_one()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
# shop/index.ludic - private names a neighbour also uses: seed, dice, LIMIT
|
||||
module shop
|
||||
var dice: int = 100
|
||||
export state ShopState {
|
||||
dice: int = 100
|
||||
}
|
||||
const LIMIT: int = 5
|
||||
function seed() -> int {
|
||||
return dice + LIMIT
|
||||
function seed(shop_st: ShopState) -> int {
|
||||
return shop_st.dice + LIMIT
|
||||
}
|
||||
export function shop_seed() -> int {
|
||||
return seed()
|
||||
export function shop_seed(shop_st: ShopState) -> int {
|
||||
return seed(shop_st)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
# weather/index.ludic - the same private spellings, its own; a local named dice is its own too
|
||||
module weather
|
||||
var dice: int = 20
|
||||
export state WeatherState {
|
||||
dice: int = 20
|
||||
}
|
||||
const LIMIT: int = 2
|
||||
function seed() -> int {
|
||||
return dice * LIMIT
|
||||
function seed(weather_st: WeatherState) -> int {
|
||||
return weather_st.dice * LIMIT
|
||||
}
|
||||
function roll(dice: int) -> int {
|
||||
return dice + 1
|
||||
}
|
||||
export function weather_seed() -> int {
|
||||
return seed() + roll(0)
|
||||
export function weather_seed(weather_st: WeatherState) -> int {
|
||||
return seed(weather_st) + roll(0)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@
|
|||
# Running it prints: 42 42
|
||||
import "bank"
|
||||
program Visible {
|
||||
var heard: int = 0
|
||||
@On(Deposited) handler Heard { heard += amount }
|
||||
entry {
|
||||
deposit(30)
|
||||
deposit(12)
|
||||
print(`{total()} {heard}`)
|
||||
state VisibleState {
|
||||
heard: int = 0
|
||||
}
|
||||
@On(Deposited) handler Heard(visible_st: mut VisibleState) { visible_st.heard += amount }
|
||||
entry (bank_st: mut BankState, visible_st: VisibleState) {
|
||||
deposit(bank_st, 30)
|
||||
deposit(bank_st, 12)
|
||||
print(`{total(bank_st)} {visible_st.heard}`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue