Standard examples (examples/standard/): - hello_world: Basic effect usage - fizzbuzz: Classic programming exercise - factorial: Recursive and tail-recursive versions - primes: Prime number generation - guessing_game: Interactive Random + Console effects - stdlib_demo: Demonstrates List, String, Option, Math modules Showcase examples (examples/showcase/): - ask_pattern: Resumable effects for config/environment - custom_logging: Custom effect with handler - early_return: Fail effect for clean error handling - effect_composition: Combining multiple effects - higher_order: Closures and function composition - pattern_matching: ADTs and exhaustive matching Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
26 lines
825 B
Plaintext
26 lines
825 B
Plaintext
// Number guessing game - demonstrates Random and Console effects
|
|
|
|
fn gameLoop(secret: Int, attempts: Int): Unit with {Console} = {
|
|
Console.print("Guess the number (1-100), attempt " + toString(attempts) + ":")
|
|
let guess = Console.readInt()
|
|
if guess == secret then
|
|
Console.print("Correct! You got it in " + toString(attempts) + " attempts!")
|
|
else if guess < secret then {
|
|
Console.print("Too low!")
|
|
gameLoop(secret, attempts + 1)
|
|
}
|
|
else {
|
|
Console.print("Too high!")
|
|
gameLoop(secret, attempts + 1)
|
|
}
|
|
}
|
|
|
|
fn main(): Unit with {Console, Random} = {
|
|
Console.print("Welcome to the Guessing Game!")
|
|
Console.print("I'm thinking of a number between 1 and 100...")
|
|
let secret = Random.int(1, 100)
|
|
gameLoop(secret, 1)
|
|
}
|
|
|
|
let output = run main() with {}
|