feat: add module import examples and standard library
Module system was already implemented - this adds examples and stdlib:
examples/modules/:
- math_utils.lux: Reusable math functions (square, cube, factorial)
- string_utils.lux: String utilities (repeat, exclaim, greet)
- main.lux: Basic module import example
- main_selective.lux: Selective imports {fn1, fn2}
- main_wildcard.lux: Wildcard imports (module.*)
- use_stdlib.lux: Using the standard library
std/:
- prelude.lux: Core utilities (identity, compose, flip, not, and, or)
- io.lux: I/O helpers (println, readLine, debug)
- option.lux: Option utilities (some, none, map, flatMap, filter)
- result.lux: Result utilities (ok, err, mapOk, mapErr)
Import syntax supports:
- import path/to/module (access as module.fn)
- import path/to/module as x (access as x.fn)
- import path/to/module.{a,b} (access as a, b directly)
- import path/to/module.* (all exports directly)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
28
std/io.lux
Normal file
28
std/io.lux
Normal file
@@ -0,0 +1,28 @@
|
||||
// Standard I/O utilities
|
||||
// Wraps Console effect with convenient functions
|
||||
|
||||
/// Print a line with a newline
|
||||
pub fn println(s: String): Unit with {Console} =
|
||||
Console.print(s)
|
||||
|
||||
/// Print without newline (if supported)
|
||||
pub fn print(s: String): Unit with {Console} =
|
||||
Console.print(s)
|
||||
|
||||
/// Read a line from input
|
||||
pub fn readLine(): String with {Console} =
|
||||
Console.readLine()
|
||||
|
||||
/// Read an integer from input
|
||||
pub fn readInt(): Int with {Console} =
|
||||
Console.readInt()
|
||||
|
||||
/// Print a debug representation of any value
|
||||
pub fn debug<T>(label: String, value: T): T with {Console} = {
|
||||
Console.print(label + ": " + toString(value))
|
||||
value
|
||||
}
|
||||
|
||||
/// Print multiple strings on separate lines
|
||||
pub fn printAll(lines: List<String>): Unit with {Console} =
|
||||
List.fold(lines, (), fn(acc: Unit, line: String): Unit with {Console} => Console.print(line))
|
||||
Reference in New Issue
Block a user