feat: eq? operator

This commit is contained in:
Roman Godmaire 2024-02-17 07:06:08 -05:00
parent fbd0070324
commit 5637d256d2
2 changed files with 17 additions and 0 deletions

View file

@ -127,6 +127,20 @@ pub fn core_environment() -> Rc<Environment> {
Ok(Rc::new(Expression::HashMap(res)))
}),
),
(
"eq?",
Expression::NativeFunc(|args| {
if args.len() != 2 {
Err(Error::MismatchedArgCount(2, args.len()))?
}
if args[0] == args[1] {
return Ok(TRUE.with(|inner| inner.clone()));
}
return Ok(FALSE.with(|inner| inner.clone()));
}),
),
(
"not",
Expression::NativeFunc(|args| {

View file

@ -219,6 +219,9 @@ mod test {
#[case("((fn* (a) a) 3)", "3")]
#[case("((fn* (a) (+ a 2)) 1)", "3")]
#[case("((fn* (a b) (+ a b)) 1 2)", "3")]
// Boolean operations
#[case("(eq? 1 1)", "true")]
#[case("(eq? 1 2)", "false")]
#[case("(not false)", "true")]
#[case("(not true)", "false")]
#[case("(not nil)", "false")]