Commit Graph

16 Commits

Author SHA1 Message Date
730112a917 feat: add stress test projects and testing documentation
- Add String.fromChar function to convert Char to String
- Create four stress test projects demonstrating Lux features:
  - json-parser: recursive descent parsing with Char handling
  - markdown-converter: string manipulation and ADTs
  - todo-app: list operations and pattern matching
  - mini-interpreter: AST evaluation and environments
- Add comprehensive testing documentation (docs/testing.md)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 18:53:27 -05:00
719bc77243 feat: add Console.readLine and Console.readInt, guessing game project
Add readLine and readInt operations to the Console effect for interactive
input. Create a number guessing game project demonstrating ADTs, pattern
matching, effects, and game state management.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 17:58:00 -05:00
296686de17 feat: add HTTP client support
Add Http effect for making HTTP requests:
- Http.get(url) - GET request
- Http.post(url, body) - POST with string body
- Http.postJson(url, json) - POST with JSON body
- Http.put(url, body) - PUT request
- Http.delete(url) - DELETE request

Returns Result<HttpResponse, String> where HttpResponse contains
status code, body, and headers.

Includes reqwest dependency with blocking client, OpenSSL support
in flake.nix, and example at examples/http.lux demonstrating
API requests with JSON parsing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 16:30:48 -05:00
ef9746c2fe feat: add JSON parsing and manipulation support
Add comprehensive JSON support via the Json module:
- Parse JSON strings with Json.parse() returning Result<Json, String>
- Stringify with Json.stringify() and Json.prettyPrint()
- Extract values with Json.get(), getIndex(), asString(), asInt(), etc.
- Build JSON with constructors: Json.null(), bool(), int(), string(), array(), object()
- Query with Json.isNull() and Json.keys()

Includes example at examples/json.lux demonstrating building, parsing,
and extracting JSON data with file I/O integration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 16:22:35 -05:00
b0f6756411 feat: add File and Process effects for real I/O
Adds two essential effects that enable Lux to interact with the system:

File effect:
- read(path) - Read file contents as string
- write(path, content) - Write string to file
- append(path, content) - Append to file
- exists(path) - Check if file/directory exists
- delete(path) - Delete a file
- readDir(path) - List directory contents
- isDir(path) - Check if path is directory
- mkdir(path) - Create directory (including parents)

Process effect:
- exec(cmd) - Run shell command, return stdout
- execStatus(cmd) - Run command, return exit code
- env(name) - Get environment variable (returns Option)
- args() - Get command line arguments
- exit(code) - Exit program with code
- cwd() - Get current working directory
- setCwd(path) - Change working directory

Also fixes formatter bug with empty handler blocks in `run ... with {}`.

These effects make Lux capable of writing real CLI tools and scripts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 16:09:20 -05:00
961a861822 feat: expand standard library with Math module and new functions
- Add Math module: abs, min, max, sqrt, pow, floor, ceil, round
- Add List functions: isEmpty, find, any, all, take, drop
- Add String functions: startsWith, endsWith, toUpper, toLower, substring
- Add 12 tests for new standard library functions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 10:15:14 -05:00
4eebaebb27 feat: implement Schema module for versioned types
Add Schema module with functions for creating and migrating versioned
values. This provides the runtime foundation for schema evolution.

Schema module functions:
- Schema.versioned(typeName, version, value) - create versioned value
- Schema.migrate(value, targetVersion) - migrate to new version
- Schema.getVersion(value) - get version number

Changes:
- Add Versioned, Migrate, GetVersion builtins to interpreter
- Add Schema module to global environment
- Add Schema module type to type environment
- Add 4 tests for schema operations
- Add examples/versioning.lux demonstrating usage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 09:59:52 -05:00
9511957076 feat: implement resumable effect handlers
Add support for the `resume(value)` expression in effect handler
bodies. When resume is called, the value becomes the return value
of the effect operation, allowing handlers to provide values back
to the calling code.

Implementation:
- Add Resume(Value) variant to EvalResult
- Add in_handler_depth tracking to Interpreter
- Update Expr::Resume evaluation to return Resume when in handler
- Handle Resume results in handle_effect to use as return value
- Add 2 tests for resumable handlers

Example usage:
```lux
handler prettyLogger: Logger {
    fn log(level, msg) = {
        Console.print("[" + level + "] " + msg)
        resume(())  // Return Unit to the call site
    }
}
```

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 09:54:51 -05:00
52ad5f8781 feat: implement Random and Time built-in effects
Add Random and Time effects for random number generation and
time-based operations. These effects can be used in any
effectful code block.

Random effect operations:
- Random.int(min, max) - random integer in range [min, max]
- Random.float() - random float in range [0.0, 1.0)
- Random.bool() - random boolean

Time effect operations:
- Time.now() - current Unix timestamp in milliseconds
- Time.sleep(ms) - sleep for specified milliseconds

Changes:
- Add rand crate dependency
- Add Random and Time effect definitions to types.rs
- Add effects to built-in effects list in typechecker
- Implement effect handlers in interpreter
- Add 4 new tests for Random and Time effects
- Add examples/random.lux demonstrating usage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 09:49:09 -05:00
c0ef71beb7 feat: implement built-in State, Reader, and Fail effects
Add runtime support for the State, Reader, and Fail effects that
were already defined in the type system. These effects can now be
used in effectful code blocks.

Changes:
- Add builtin_state and builtin_reader fields to Interpreter
- Implement State.get and State.put in handle_builtin_effect
- Implement Reader.ask in handle_builtin_effect
- Add Reader effect definition to types.rs
- Add Reader to built-in effects list in typechecker
- Add set_state/get_state/set_reader/get_reader methods
- Add 6 new tests for built-in effects
- Add examples/builtin_effects.lux demonstrating usage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 09:46:13 -05:00
f670bd2659 feat: implement string interpolation
Add support for string interpolation with {expr} syntax:
  "Hello, {name}!" becomes "Hello, " + toString(name) + "!"

Lexer changes:
- Add StringPart enum (Literal/Expr) and InterpolatedString token
- Detect {expr} in strings and capture expression text
- Support escaped braces with \{ and \}

Parser changes:
- Add desugar_interpolated_string() to convert to concatenation
- Automatically wrap expressions in toString() calls

Interpreter changes:
- Fix toString() to not add quotes around strings

Tests added:
- 4 lexer tests for interpolation tokenization
- 4 integration tests for full interpolation pipeline

Add examples/interpolation.lux demonstrating:
- Variable interpolation
- Number interpolation (auto toString)
- Expression interpolation ({a + b})
- Escaped braces

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 09:30:37 -05:00
15a820a467 fix: make all example programs work correctly
- Add string concatenation support to + operator in typechecker
- Register ADT constructors in both type environment and interpreter
- Bind handlers as values so they can be referenced in run...with
- Fix effect checking to use subset instead of exact match
- Add built-in effects (Console, Fail, State) to run block contexts
- Suppress dead code warnings in diagnostics, modules, parser

Update all example programs with:
- Expected output documented in comments
- Proper run...with statements to execute code

Add new example programs:
- behavioral.lux: pure, idempotent, deterministic, commutative functions
- pipelines.lux: pipe operator demonstrations
- statemachine.lux: ADT-based state machines
- tailcall.lux: tail call optimization examples
- traits.lux: type classes and pattern matching

Add documentation:
- docs/IMPLEMENTATION_PLAN.md: feature roadmap and status
- docs/PERFORMANCE_AND_TRADEOFFS.md: performance analysis

Add benchmarks for performance testing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 09:05:06 -05:00
05a85ea27f feat: implement type classes / traits
Add support for type classes (traits) with full parsing, type checking, and
validation. The implementation includes:

- Trait declarations: trait Show { fn show(x: T): String }
- Trait implementations: impl Show for Int { fn show(x: Int) = ... }
- Super traits: trait Ord: Eq { ... }
- Trait constraints in where clauses: where T: Show + Eq
- Type parameters on traits: trait Functor<F> { ... }
- Default method implementations
- Validation of required method implementations

This provides a foundation for ad-hoc polymorphism and enables
more expressive type-safe abstractions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 04:51:06 -05:00
df5c0a1a32 feat: implement tail call optimization (TCO)
Add trampoline-based tail call optimization to prevent stack overflow
on deeply recursive tail-recursive functions. The implementation:

- Extends EvalResult with TailCall variant for deferred evaluation
- Adds trampoline loop in eval_expr() to handle tail calls iteratively
- Propagates tail position through If, Let, Match, and Block expressions
- Updates all builtin callbacks to handle tail calls via eval_call_to_value
- Includes tests for deep recursion (10000+ calls) and accumulator patterns

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 04:42:53 -05:00
d37f0fb096 Add Elm-style error diagnostics
Implement beautiful, informative error messages inspired by Elm:
- Rich diagnostic rendering with source code snippets
- Colored output with proper underlines showing error locations
- Categorized error titles (Type Mismatch, Unknown Name, etc.)
- Contextual hints and suggestions for common errors
- Support for type errors, runtime errors, and parse errors

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 04:01:49 -05:00
15e5ccb064 init lux 2026-02-13 02:57:01 -05:00