feat(lang): L3 module scope - module, export, friend module
A barrel's 'module NAME' makes its directory a module; a declaration other modules use says 'export'. Private use from another module is an error naming the module and where to mark it; 'friend module' sees everything (a test harness); a file in no module is public and a package keeps its own module. LUDIC_VIS_REPORT=1 lists every violation instead of stopping, so a codebase can be given its exports first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0c73287e35
commit
0677aee93f
20 changed files with 55913 additions and 54132 deletions
3
examples/modules/bank/index.ludic
Normal file
3
examples/modules/bank/index.ludic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# bank/index.ludic - a module: only what it exports is reachable from outside
|
||||
module bank
|
||||
import "ledger.ludic"
|
||||
13
examples/modules/bank/ledger.ludic
Normal file
13
examples/modules/bank/ledger.ludic
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# 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 function deposit(n: int) -> void {
|
||||
add(n)
|
||||
emit Deposited(amount: n)
|
||||
}
|
||||
export function total() -> int {
|
||||
return balance
|
||||
}
|
||||
14
examples/modules/visible.ludic
Normal file
14
examples/modules/visible.ludic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# visible.ludic — L3: a program in no module uses what module bank exports: a function to call
|
||||
# and an event to listen to. Its private `add` and `balance` stay out of reach.
|
||||
#
|
||||
# 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}`)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue