From 01871bf45531f63b0dc0b7b07adb0accb02ab1f0 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 28 Jan 2025 06:14:05 -0600 Subject: [PATCH] cl-interpret: `get_line` builtin! --- compiler/cl-interpret/src/builtin.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/cl-interpret/src/builtin.rs b/compiler/cl-interpret/src/builtin.rs index 08e0868..652b370 100644 --- a/compiler/cl-interpret/src/builtin.rs +++ b/compiler/cl-interpret/src/builtin.rs @@ -59,6 +59,7 @@ builtins! { Ok(ConValue::Empty) } + /// Gets the length of a container or range pub fn len(list) -> IResult { Ok(ConValue::Int(match list { ConValue::Empty => 0, @@ -71,6 +72,14 @@ builtins! { _ => Err(Error::TypeError)?, })) } + + /// Gets a line of text from stdin + pub fn get_line() -> IResult { + let mut line = String::new(); + let _ = std::io::stdin().read_line(&mut line); + Ok(ConValue::String(line.into())) + } + /// Lists the potential "upvars" (lifted environment) of a function pub fn collect_upvars(ConValue::Function(f)) -> IResult { use crate::function::collect_upvars::collect_upvars;