feat: basic string coercion

This commit is contained in:
Roman Godmaire 2024-05-04 17:10:51 -04:00
parent 0af757fa27
commit 92b32ff2df
2 changed files with 13 additions and 0 deletions

10
src/env/core.rs vendored
View file

@ -300,6 +300,16 @@ pub(super) fn core() -> HashMap<String, Node> {
}) })
}), }),
), ),
// Strings
(
"str",
Node::NativeFunc(|_env, args| {
arg_count!(1, args.len());
let val = args[0].borrow();
Ok(Node::String(val.to_string()))
}),
),
// IO // IO
( (
"display", "display",

View file

@ -156,6 +156,9 @@ mod test {
#[case("(>= 2 1)", "true")] #[case("(>= 2 1)", "true")]
#[case("(>= 1 1)", "true")] #[case("(>= 1 1)", "true")]
#[case("(>= 1 2)", "false")] #[case("(>= 1 2)", "false")]
// Strings
#[case("(str (+ 1 2))", "3")]
#[case("(str (list 1 2 3))", "(1 2 3)")]
fn test_evaluator(#[case] input: &str, #[case] expected: &str) { fn test_evaluator(#[case] input: &str, #[case] expected: &str) {
let env = Environment::new(); let env = Environment::new();
let ast = parser::parse_str(input).unwrap(); let ast = parser::parse_str(input).unwrap();