Files
Minus 83629d0e1e imports: use name imports by module name
`use` only accepted a path expression, so `use math` read `math` as a
global and failed.  Now the operand may be a bare module name.

- compiler: `use NAME` emits the name as a constant (a path expression
  still works, e.g. `use "std/io/io.cat"` or `use (expr)`).
- stdlib: `use_resolve` maps a name to a path, trying, in order:
  <name>, <name>.cat, std/<name>/<name>.cat, <name>/<name>.cat,
  std/<name>.cat.  A path (contains `.cat` or `/`) is used as-is.
- stdlib: a missing module now raises (per project rule: no silent
  failure) -- "cannot import module 'X'" -- instead of doing nothing.
- tests/import.cat: `use math`, `use io` and a path string (109 total,
  all green).
2026-11-17 18:40:10 +00:00

17 lines
484 B
Plaintext

-- tests/import.cat -- `use name` imports by module name.
--
-- The operand is a bare module name (`math`) or a path string. A name
-- resolves (in order) to: <name>, <name>.cat, std/<name>/<name>.cat,
-- <name>/<name>.cat, std/<name>.cat. A path is used as-is.
use math
print("double 21 =", double(21))
print("square 7 =", square(7))
use io
print("join:", join({"a", "b", "c"}, "-"))
-- a path string still works (used as-is)
use "std/math/math.cat"
print("abs(-5) =", abs(-5))