feat(lang): a module's private names are its own

A private function, var or const no longer collides with the same
spelling in another module, in no module or in the runtime: where two
meet, each private one is renamed for its module (seed$shop), with every
reference its module writes that no local shadows. Exported names stay
one namespace. Nothing is renamed without a clash. Reseed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 07:08:05 +03:00
parent c9dc592dcc
commit a09b622a1d
14 changed files with 49752 additions and 44752 deletions

View file

@ -0,0 +1,15 @@
# private_twins.ludic — L3: a module's private names are its own. shop and weather each have a
# private `seed`, `dice` and `LIMIT`, and the program has a `seed` of its own; none of them collide,
# and each module's code reaches its own.
#
# Running it prints: 105 41 7
import "twins/shop"
import "twins/weather"
program PrivateTwins {
function seed() -> int {
return 7
}
entry {
print(`{shop_seed()} {weather_seed()} {seed()}`)
}
}

View file

@ -0,0 +1,10 @@
# shop/index.ludic - private names a neighbour also uses: seed, dice, LIMIT
module shop
var dice: int = 100
const LIMIT: int = 5
function seed() -> int {
return dice + LIMIT
}
export function shop_seed() -> int {
return seed()
}

View file

@ -0,0 +1,13 @@
# weather/index.ludic - the same private spellings, its own; a local named dice is its own too
module weather
var dice: int = 20
const LIMIT: int = 2
function seed() -> int {
return dice * LIMIT
}
function roll(dice: int) -> int {
return dice + 1
}
export function weather_seed() -> int {
return seed() + roll(0)
}

View file

@ -0,0 +1,8 @@
# L3: two modules that both EXPORT a name clash - only private names are a module's own
import "exported_twins/a"
import "exported_twins/b"
program ExportedTwins {
entry {
print(seed())
}
}

View file

@ -0,0 +1,5 @@
# a/index.ludic - exports seed
module a
export function seed() -> int {
return 1
}

View file

@ -0,0 +1,5 @@
# b/index.ludic - exports seed too: exported names are one namespace
module b
export function seed() -> int {
return 2
}