ombre: Implement `!=`
fb4a054b9be709a9462a26206e593199c077729e
1 parent
1a46e757
ombre/src/lisp/evaluator.rs
+10 -0
| 1061 | 1061 | "or", |
|
| 1062 | 1062 | "Logical *or* of two or more boolean values", |
|
| 1063 | 1063 | intrinsic::or, |
|
| 1064 | 1064 | ); |
|
| 1065 | 1065 | env.intrinsic("=", "Check if all arguments are equal", intrinsic::eq); |
|
| 1066 | + | env.intrinsic("!=", "Check if any arguments are not equal", intrinsic::neq); |
|
| 1066 | 1067 | env.intrinsic( |
|
| 1067 | 1068 | ">", |
|
| 1068 | 1069 | "Check if the first argument is greater than the second", |
|
| 1069 | 1070 | intrinsic::gt, |
|
| 1070 | 1071 | ); |
| 1840 | 1841 | return Err(Error::ExpectedValue("expression")); |
|
| 1841 | 1842 | }; |
|
| 1842 | 1843 | Ok(Expr::Bool(args.all(|a| a == head))) |
|
| 1843 | 1844 | } |
|
| 1844 | 1845 | ||
| 1846 | + | /// Not equals (!=). |
|
| 1847 | + | pub fn neq(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 1848 | + | let mut args = args.into_iter(); |
|
| 1849 | + | let Some(head) = args.next() else { |
|
| 1850 | + | return Err(Error::ExpectedValue("expression")); |
|
| 1851 | + | }; |
|
| 1852 | + | Ok(Expr::Bool(args.any(|a| a != head))) |
|
| 1853 | + | } |
|
| 1854 | + | ||
| 1845 | 1855 | /// Addition (+). |
|
| 1846 | 1856 | pub fn add(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 1847 | 1857 | let mut args = args.into_iter(); |
|
| 1848 | 1858 | match args.next() { |
|
| 1849 | 1859 | Some(Expr::Vector2D(v)) => fold(args, v, |acc, v| acc + v), |