feat: add list constructor
This commit is contained in:
parent
c38576b667
commit
769cc61d48
2 changed files with 22 additions and 2 deletions
13
src/env/core.rs
vendored
13
src/env/core.rs
vendored
|
@ -66,6 +66,19 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
}),
|
||||
),
|
||||
// Collections
|
||||
("list", Node::NativeFunc(|_env, args| Ok(Node::List(args)))),
|
||||
(
|
||||
"list?",
|
||||
Node::NativeFunc(|_env, args| {
|
||||
arg_count!(1, args.len());
|
||||
|
||||
if let Node::List(_list) = args[0].borrow() {
|
||||
return Ok(Node::Boolean(true));
|
||||
}
|
||||
|
||||
Ok(Node::Boolean(false))
|
||||
}),
|
||||
),
|
||||
(
|
||||
"vector",
|
||||
Node::NativeFunc(|_env, args| Ok(Node::Vector(args))),
|
||||
|
|
|
@ -93,21 +93,28 @@ mod test {
|
|||
#[case("(- 5 1)", "4")]
|
||||
#[case("(* 8 9)", "72")]
|
||||
#[case("(/ 86 2)", "43")]
|
||||
// Native functions
|
||||
#[case("(+ 1 2 (- 3 4))", "2")]
|
||||
#[case("(vector 1 2 3)", "[1 2 3]")]
|
||||
// Native functions defaults
|
||||
#[case("(+)", "0")]
|
||||
#[case("(-)", "0")]
|
||||
#[case("(*)", "0")]
|
||||
#[case("(/)", "0")]
|
||||
#[case("(vector)", "[]")]
|
||||
#[case("(hashmap)", "{}")]
|
||||
#[case("(list)", "()")]
|
||||
// Collections
|
||||
#[case("[]", "[]")]
|
||||
#[case("[1 2]", "[1 2]")]
|
||||
#[case("[1 (+ 1 2)]", "[1 3]")]
|
||||
#[case("{}", "{}")]
|
||||
#[case("{:a \"uwu\"}", "{:a: uwu}")]
|
||||
#[case("(list 1 2 3)", "(1 2 3)")]
|
||||
#[case("(list? (list))", "true")]
|
||||
#[case("(vector 1 2 3)", "[1 2 3]")]
|
||||
#[case("(vector? [])", "true")]
|
||||
// Unsure how to test this due to hashmaps being unordered
|
||||
// #[case("(hashmap :a 1 :b 2)", "{:a: 1, :b: 2}")]
|
||||
#[case("(hashmap? {})", "true")]
|
||||
// Environment manipulation
|
||||
#[case("(define! asdf (+ 2 2)) (+ asdf 2)", "4\n6")]
|
||||
#[case("(let* (a 2) (+ a 2))", "4")]
|
||||
|
|
Loading…
Reference in a new issue