feat(lang): ports - port Clock { ... } in a module, bind Clock { ... } in the app
A port is a record of function values a module calls through (Clock.now()) without naming the module that answers. A port used and never bound, a bind missing a required member or naming one the port lacks, and a second bind are refused; the binder must see the port, and what it binds is checked from its own file. Reseed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d0ad364ad4
commit
b1ccaf08bd
19 changed files with 50439 additions and 47750 deletions
6
examples/rejected/port_clock/index.ludic
Normal file
6
examples/rejected/port_clock/index.ludic
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# port_clock/index.ludic - a port that is not exported
|
||||
module clock
|
||||
port Clock { now: fn() -> int }
|
||||
export function tell() -> int {
|
||||
return Clock.now()
|
||||
}
|
||||
14
examples/rejected/port_missing.ludic
Normal file
14
examples/rejected/port_missing.ludic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# L3: a bind gives every member that has no default
|
||||
program PortMissing {
|
||||
port Clock {
|
||||
now: fn() -> int
|
||||
day: fn() -> int
|
||||
}
|
||||
function hours() -> int {
|
||||
return 3
|
||||
}
|
||||
bind Clock { now: fn hours }
|
||||
entry {
|
||||
print(Clock.now())
|
||||
}
|
||||
}
|
||||
11
examples/rejected/port_private.ludic
Normal file
11
examples/rejected/port_private.ludic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# L3: whoever binds a port has to see it - clock's Clock is not exported
|
||||
import "port_clock"
|
||||
program PortPrivate {
|
||||
function hours() -> int {
|
||||
return 3
|
||||
}
|
||||
bind Clock { now: fn hours }
|
||||
entry {
|
||||
print(tell())
|
||||
}
|
||||
}
|
||||
15
examples/rejected/port_twice.ludic
Normal file
15
examples/rejected/port_twice.ludic
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# L3: a port is bound once
|
||||
program PortTwice {
|
||||
port Clock { now: fn() -> int }
|
||||
function hours() -> int {
|
||||
return 3
|
||||
}
|
||||
function minutes() -> int {
|
||||
return 4
|
||||
}
|
||||
bind Clock { now: fn hours }
|
||||
bind Clock { now: fn minutes }
|
||||
entry {
|
||||
print(Clock.now())
|
||||
}
|
||||
}
|
||||
7
examples/rejected/port_unbound.ludic
Normal file
7
examples/rejected/port_unbound.ludic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# L3: a port that is used and never bound is a program not yet put together
|
||||
program PortUnbound {
|
||||
port Clock { now: fn() -> int }
|
||||
entry {
|
||||
print(Clock.now())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue