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>
This commit is contained in:
2026-02-13 17:58:00 -05:00
parent 44f88afcf8
commit 719bc77243
3 changed files with 231 additions and 1 deletions

View File

@@ -2880,7 +2880,7 @@ impl Interpreter {
Ok(Value::Unit)
}
}
("Console", "read") => {
("Console", "read") | ("Console", "readLine") => {
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
@@ -2890,6 +2890,23 @@ impl Interpreter {
})?;
Ok(Value::String(input.trim().to_string()))
}
("Console", "readInt") => {
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.map_err(|e| RuntimeError {
message: format!("Failed to read input: {}", e),
span: None,
})?;
let trimmed = input.trim();
match trimmed.parse::<i64>() {
Ok(n) => Ok(Value::Int(n)),
Err(_) => Err(RuntimeError {
message: format!("Invalid integer: '{}'", trimmed),
span: None,
}),
}
}
("Fail", "fail") => {
let msg = request
.args