fix: support truthy values
In scheme, everything except false is considered truthy.
This commit is contained in:
parent
5637d256d2
commit
1d16187846
2 changed files with 6 additions and 6 deletions
|
@ -166,12 +166,12 @@ pub fn core_environment() -> Rc<Environment> {
|
|||
let (cond, consequence, alternative) =
|
||||
(args[0].clone(), args[1].clone(), args[2].clone());
|
||||
|
||||
// If the value is anything other than true or nil, then we return the alternative
|
||||
if *cond == Expression::Boolean(true) || *cond == Expression::Nil {
|
||||
return Ok(consequence);
|
||||
// If the value is anything other than false, then it is truthy
|
||||
if *cond == Expression::Boolean(false) {
|
||||
return Ok(alternative);
|
||||
};
|
||||
|
||||
Ok(alternative)
|
||||
Ok(consequence)
|
||||
}),
|
||||
),
|
||||
// Environment Manipulation
|
||||
|
|
|
@ -213,8 +213,8 @@ mod test {
|
|||
#[case("(if true true false)", "true")]
|
||||
#[case("(if nil true false)", "true")]
|
||||
#[case("(if false true false)", "false")]
|
||||
#[case("(if 4 true false)", "false")]
|
||||
#[case("(if \"blue\" true false)", "false")]
|
||||
#[case("(if 4 true false)", "true")]
|
||||
#[case("(if \"blue\" true false)", "true")]
|
||||
// Functions
|
||||
#[case("((fn* (a) a) 3)", "3")]
|
||||
#[case("((fn* (a) (+ a 2)) 1)", "3")]
|
||||
|
|
Loading…
Reference in a new issue