fix: fix examples to use working patterns
- behavioral.lux: use verifiable behavioral patterns (abs for idempotent) - behavioral_types.lux: use simpler verified patterns, proper main invocation - schema_evolution.lux: simplify to runtime schema ops, fix record access - jit_test.lux: add proper main function with console output All examples now parse and run correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,20 +3,14 @@
|
||||
//
|
||||
// Expected output:
|
||||
// add(5, 3) = 8
|
||||
// clamp(150, 0, 100) = 100
|
||||
// factorial(5) = 120
|
||||
// multiply(7, 6) = 42
|
||||
// abs(-5) = 5
|
||||
|
||||
// A pure function - no side effects, same input always gives same output
|
||||
fn add(a: Int, b: Int): Int is pure =
|
||||
a + b
|
||||
|
||||
// An idempotent function - applying twice gives same result as once
|
||||
fn clamp(value: Int, min: Int, max: Int): Int is idempotent =
|
||||
if value < min then min
|
||||
else if value > max then max
|
||||
else value
|
||||
|
||||
// A deterministic function - same input always gives same output
|
||||
fn factorial(n: Int): Int is deterministic =
|
||||
if n <= 1 then 1
|
||||
@@ -26,18 +20,22 @@ fn factorial(n: Int): Int is deterministic =
|
||||
fn multiply(a: Int, b: Int): Int is commutative =
|
||||
a * b
|
||||
|
||||
// An idempotent function - absolute value
|
||||
fn abs(x: Int): Int is idempotent =
|
||||
if x < 0 then 0 - x else x
|
||||
|
||||
// Test the functions
|
||||
let sumResult = add(5, 3)
|
||||
let clampedResult = clamp(150, 0, 100)
|
||||
let factResult = factorial(5)
|
||||
let productResult = multiply(7, 6)
|
||||
let absResult = abs(0 - 5)
|
||||
|
||||
// Print results
|
||||
fn printResults(): Unit with {Console} = {
|
||||
Console.print("add(5, 3) = " + toString(sumResult))
|
||||
Console.print("clamp(150, 0, 100) = " + toString(clampedResult))
|
||||
Console.print("factorial(5) = " + toString(factResult))
|
||||
Console.print("multiply(7, 6) = " + toString(productResult))
|
||||
Console.print("abs(-5) = " + toString(absResult))
|
||||
}
|
||||
|
||||
let output = run printResults() with {}
|
||||
|
||||
Reference in New Issue
Block a user