ludic/examples/modules/port_vars.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

24 lines
722 B
Text

# port_vars.ludic — L3: a port member that takes nothing can be bound to a variable, `money: g_money`
# - the compiler writes the getter (bind_Purse_money) in the bind's own file - and a member that takes
# something is still bound to a function.
#
# Running it prints: 40 45 12
program PortVars {
port Purse {
money: fn() -> int
price: fn(int) -> int
}
state PortVarsState {
g_money: int = 40
}
let g_rate: int = 3
function priced(n: int) -> int {
return n * g_rate
}
bind Purse { money: PortVarsState.g_money, price: fn priced }
entry (port_vars_st: mut PortVarsState) {
let a = Purse.money()
port_vars_st.g_money += 5
print(`{a} {Purse.money()} {Purse.price(4)}`)
}
}