aethershell 12.0.1

The world's first multi-agent shell with typed functional pipelines and multi-modal AI
#!/usr/bin/env ae
# Example 17: Parser Improvements
# Demonstrates improved syntax: semicolons, pipeline assignments, zero-param lambdas

# ============================================================================
# Semicolon Statement Separation
# ============================================================================

print("=== Semicolon Separation ===")

# Multiple statements on one line
x = 5; y = 10; z = x + y
print("x + y = " + "${z}")

# Pipe followed by semicolon and another statement
let mut items = [1,2,3] | reverse; print("Reversed: " + "${data}")

# Chain multiple operations
a = 1; b = 2; c = 3; print("Sum: " + "${a + b + c}")

# ============================================================================
# Pipeline Assignments Without Parentheses
# ============================================================================

print("\n=== Pipeline Assignments ===")

# Direct pipeline assignment (no parentheses needed!)
nums = [5, 3, 1, 4, 2] | sort
print("Sorted: " + "${nums}")

# Chained pipelines
doubled = [1, 2, 3] | map(fn(x) => x * 2)
print("Doubled: " + "${doubled}")

# Multiple pipeline assignments
evens = [1, 2, 3, 4, 5, 6] | where(fn(x) => x % 2 == 0)
odds = [1, 2, 3, 4, 5, 6] | where(fn(x) => x % 2 != 0)
print("Evens: " + "${evens}")
print("Odds: " + "${odds}")

# Complex pipeline
let mut result = [1,2,3,4,5] | map(fn(x) => x * 2) | where(fn(x) => x > 4) | sum
print("Filtered sum: " + "${result}")

# ============================================================================
# Zero-Parameter Lambdas
# ============================================================================

print("\n=== Zero-Parameter Lambdas ===")

# Simple thunk
get_answer = fn() => 42
print("Answer: " + "${get_answer()}")

# String thunk
greeting = fn() => "Hello, World!"
print(greeting())

# Closure capturing outer variable
name = "AetherShell"
say_hello = fn() => "Hello from " + name
print(say_hello())

# Factory pattern
make_counter = fn() => 0
c1 = make_counter()
c2 = make_counter()
print("Counters: " + "${c1}" + ", " + "${c2}")

# Deferred computation
expensive = fn() => 100 * 100
print("Expensive result: " + "${expensive()}")

# IIFE (Immediately Invoked Function Expression)
immediate = (fn() => "Immediate!")()
print(immediate)

# ============================================================================
# Combining All Features
# ============================================================================

print("\n=== Combined Examples ===")

# Multiple statements with pipelines and closures on one line
items = [1,2,3] | reverse; transform = fn() => items | map(fn(x) => x * 10); print("Transformed: " + "${transform()}")

# Pipeline with zero-param lambda
get_data = fn() => [10, 20, 30]
total = get_data() | sum
print("Total: " + "${total}")

# Array of thunks
thunks = [fn() => 1, fn() => 2, fn() => 3]
results = thunks | map(fn(t) => t())
print("Thunk results: " + "${results}")