ombre: Implement dictionary operations
295191b83b3cc4b56822c30fc45f98acead692bb
1 parent
5e59307a
ombre/src/lang/evaluator.rs
+117 -16
| 3 | 3 | use std::collections::HashSet; |
|
| 4 | 4 | use std::hash::{Hash, Hasher}; |
|
| 5 | 5 | use std::ops::{Deref, DerefMut}; |
|
| 6 | 6 | use std::path::PathBuf; |
|
| 7 | 7 | use std::rc::Rc; |
|
| 8 | - | use std::{collections::HashMap, iter::Peekable}; |
|
| 8 | + | use std::{ |
|
| 9 | + | collections::{BTreeMap, HashMap}, |
|
| 10 | + | iter::Peekable, |
|
| 11 | + | }; |
|
| 9 | 12 | use std::{fmt, fs, iter, result}; |
|
| 10 | 13 | ||
| 11 | 14 | use crate::gfx::Rgba; |
|
| 12 | 15 | use crate::lang::dynamic::{Dynamic, IsDynamic}; |
|
| 13 | 16 | use crate::math::{Vector2D, Vector3D, Vector4D}; |
| 71 | 74 | self.0.fmt(f) |
|
| 72 | 75 | } |
|
| 73 | 76 | } |
|
| 74 | 77 | ||
| 75 | 78 | /// Values that can be used as dictionary keys. |
|
| 76 | - | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
|
| 79 | + | #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] |
|
| 77 | 80 | pub enum Key { |
|
| 78 | 81 | /// Eg. true |
|
| 79 | 82 | Bool(bool), |
|
| 80 | 83 | /// Eg. :yikes |
|
| 81 | 84 | Atom(Rc<str>), |
| 213 | 216 | /// Eg. (vec3 x y z) |
|
| 214 | 217 | Vector3D(Vector3D<f64>), |
|
| 215 | 218 | /// Eg. (vec4 x y z w) |
|
| 216 | 219 | Vector4D(Vector4D<f64>), |
|
| 217 | 220 | /// Eg. (dict {:a 1 :b 2 :c 3}) |
|
| 218 | - | Dict(Mut<HashMap<Key, Expr>>), |
|
| 221 | + | Dict(Mut<BTreeMap<Key, Expr>>), |
|
| 219 | 222 | /// Eg. fnord |
|
| 220 | 223 | Symbol(Symbol), |
|
| 221 | 224 | /// Eg. :yikes |
|
| 222 | 225 | Atom(Rc<str>), |
|
| 223 | 226 | /// Eg. "fnord" |
| 253 | 256 | pub fn vector(items: impl Into<Vec<Expr>>) -> Self { |
|
| 254 | 257 | Expr::Vector(Rc::from(RefCell::new(items.into()))) |
|
| 255 | 258 | } |
|
| 256 | 259 | ||
| 257 | 260 | /// Construct a dictionary. |
|
| 258 | - | pub fn dict(items: HashMap<Key, Expr>) -> Self { |
|
| 261 | + | pub fn dict(items: BTreeMap<Key, Expr>) -> Self { |
|
| 259 | 262 | Expr::Dict(Rc::from(RefCell::new(items))) |
|
| 260 | 263 | } |
|
| 261 | 264 | ||
| 262 | 265 | /// Construct a symbol. |
|
| 263 | 266 | pub fn symbol(name: impl Into<Symbol>) -> Self { |
| 364 | 367 | _ => Err(expr), |
|
| 365 | 368 | } |
|
| 366 | 369 | } |
|
| 367 | 370 | } |
|
| 368 | 371 | ||
| 369 | - | impl TryFrom<Expr> for Mut<HashMap<Key, Expr>> { |
|
| 372 | + | impl TryFrom<Expr> for Mut<BTreeMap<Key, Expr>> { |
|
| 370 | 373 | type Error = Expr; |
|
| 371 | 374 | ||
| 372 | 375 | fn try_from(expr: Expr) -> std::result::Result<Self, Self::Error> { |
|
| 373 | 376 | match expr { |
|
| 374 | 377 | Expr::Dict(d) => Ok(d), |
| 492 | 495 | fn from(v: Vector4D<f64>) -> Self { |
|
| 493 | 496 | Expr::Vector4D(v) |
|
| 494 | 497 | } |
|
| 495 | 498 | } |
|
| 496 | 499 | ||
| 500 | + | impl From<Key> for Expr { |
|
| 501 | + | fn from(k: Key) -> Self { |
|
| 502 | + | match k { |
|
| 503 | + | Key::Bool(b) => Expr::Bool(b), |
|
| 504 | + | Key::Atom(s) => Expr::Atom(s), |
|
| 505 | + | Key::Str(s) => Expr::Str(s), |
|
| 506 | + | Key::Integer(n) => Expr::Integer(n), |
|
| 507 | + | Key::Char(c) => Expr::Char(c), |
|
| 508 | + | } |
|
| 509 | + | } |
|
| 510 | + | } |
|
| 511 | + | ||
| 497 | 512 | /// Helper enum for handling multiple possible types. |
|
| 498 | 513 | enum Either<L, R> { |
|
| 499 | 514 | Left(L), |
|
| 500 | 515 | Right(R), |
|
| 501 | 516 | } |
| 1143 | 1158 | env.intrinsic( |
|
| 1144 | 1159 | "modify!", |
|
| 1145 | 1160 | "Modify a mutable reference in-place using a lambda", |
|
| 1146 | 1161 | intrinsic::modify, |
|
| 1147 | 1162 | ); |
|
| 1163 | + | env.intrinsic( |
|
| 1164 | + | "keys", |
|
| 1165 | + | "Get all keys from a dictionary as a tuple", |
|
| 1166 | + | intrinsic::keys, |
|
| 1167 | + | ); |
|
| 1168 | + | env.intrinsic( |
|
| 1169 | + | "values", |
|
| 1170 | + | "Get all values from a dictionary as a tuple", |
|
| 1171 | + | intrinsic::values, |
|
| 1172 | + | ); |
|
| 1173 | + | env.intrinsic( |
|
| 1174 | + | "pairs", |
|
| 1175 | + | "Get key-value pairs from a dictionary", |
|
| 1176 | + | intrinsic::pairs, |
|
| 1177 | + | ); |
|
| 1178 | + | env.intrinsic( |
|
| 1179 | + | "merge", |
|
| 1180 | + | "Merge two dictionaries, with right values overriding left ones", |
|
| 1181 | + | intrinsic::merge, |
|
| 1182 | + | ); |
|
| 1148 | 1183 | env.intrinsic( |
|
| 1149 | 1184 | "vec2", |
|
| 1150 | 1185 | "Create a 2D vector from x,y components", |
|
| 1151 | 1186 | intrinsic::vec2, |
|
| 1152 | 1187 | ); |
| 1465 | 1500 | Expr::Dict(d) => d |
|
| 1466 | 1501 | .borrow() |
|
| 1467 | 1502 | .clone() |
|
| 1468 | 1503 | .into_iter() |
|
| 1469 | 1504 | .map(|(k, v)| eval(v, env).map(|v| (k, v))) |
|
| 1470 | - | .collect::<Result<HashMap<_, _>>>() |
|
| 1505 | + | .collect::<Result<BTreeMap<_, _>>>() |
|
| 1471 | 1506 | .map(Expr::dict), |
|
| 1472 | 1507 | Expr::Ref(r) => Ok(Expr::Ref(r)), |
|
| 1473 | 1508 | Expr::Dynamic(d) => Ok(Expr::Dynamic(d)), |
|
| 1474 | 1509 | } |
|
| 1475 | 1510 | } |
| 1652 | 1687 | } |
|
| 1653 | 1688 | ||
| 1654 | 1689 | /// Create a dictionary. |
|
| 1655 | 1690 | pub fn dict(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 1656 | 1691 | if args.is_empty() { |
|
| 1657 | - | return Ok(Expr::dict(HashMap::new())); |
|
| 1692 | + | return Ok(Expr::dict(BTreeMap::new())); |
|
| 1658 | 1693 | } |
|
| 1659 | 1694 | let (list,) = <(Vec<Expr>,)>::try_from_args(args)?; |
|
| 1660 | - | let mut dict = HashMap::new(); |
|
| 1695 | + | let mut dict = BTreeMap::new(); |
|
| 1661 | 1696 | let mut iter = list.into_iter(); |
|
| 1662 | 1697 | ||
| 1663 | 1698 | while let Some(k) = iter.next() { |
|
| 1664 | 1699 | let Some(v) = iter.next() else { |
|
| 1665 | 1700 | return Err(Error::ExpectedValue("any")); |
| 1673 | 1708 | Ok(Expr::dict(dict)) |
|
| 1674 | 1709 | } |
|
| 1675 | 1710 | ||
| 1676 | 1711 | /// Lookup a value in a dictionary. |
|
| 1677 | 1712 | pub fn get(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 1678 | - | let (dict, key) = <(Mut<HashMap<Key, Expr>>, Key)>::try_from_args(args)?; |
|
| 1713 | + | let (dict, key) = <(Mut<BTreeMap<Key, Expr>>, Key)>::try_from_args(args)?; |
|
| 1679 | 1714 | let d = dict.borrow(); |
|
| 1680 | 1715 | ||
| 1681 | 1716 | if let Some(v) = d.get(&key) { |
|
| 1682 | 1717 | Ok(v.clone()) |
|
| 1683 | 1718 | } else { |
| 1685 | 1720 | } |
|
| 1686 | 1721 | } |
|
| 1687 | 1722 | ||
| 1688 | 1723 | /// Set a value under a key in a dictionary. |
|
| 1689 | 1724 | pub fn put(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 1690 | - | let (dict, key, val) = <(Mut<HashMap<Key, Expr>>, Key, Expr)>::try_from_args(args)?; |
|
| 1725 | + | let (dict, key, val) = <(Mut<BTreeMap<Key, Expr>>, Key, Expr)>::try_from_args(args)?; |
|
| 1691 | 1726 | let mut d = dict.borrow_mut(); |
|
| 1692 | 1727 | ||
| 1693 | 1728 | if let Some(old) = d.insert(key, val) { |
|
| 1694 | 1729 | Ok(old) |
|
| 1695 | 1730 | } else { |
| 2029 | 2064 | *old = new; |
|
| 2030 | 2065 | ||
| 2031 | 2066 | Ok(Expr::Nil) |
|
| 2032 | 2067 | } |
|
| 2033 | 2068 | ||
| 2069 | + | /// Get all keys from a dictionary as a tuple. |
|
| 2070 | + | pub fn keys(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 2071 | + | let (dict,) = <(Mut<BTreeMap<Key, Expr>>,)>::try_from_args(args)?; |
|
| 2072 | + | let keys = dict.borrow().keys().cloned().map(Expr::from).collect::<Vec<_>>(); |
|
| 2073 | + | ||
| 2074 | + | Ok(Expr::tuple(keys)) |
|
| 2075 | + | } |
|
| 2076 | + | ||
| 2077 | + | /// Get all values from a dictionary as a tuple. |
|
| 2078 | + | pub fn values(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 2079 | + | let (dict,) = <(Mut<BTreeMap<Key, Expr>>,)>::try_from_args(args)?; |
|
| 2080 | + | let values = dict.borrow().values().cloned().collect::<Vec<_>>(); |
|
| 2081 | + | ||
| 2082 | + | Ok(Expr::tuple(values)) |
|
| 2083 | + | } |
|
| 2084 | + | ||
| 2085 | + | /// Get key-value pairs from a dictionary. |
|
| 2086 | + | pub fn pairs(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 2087 | + | let (dict,) = <(Mut<BTreeMap<Key, Expr>>,)>::try_from_args(args)?; |
|
| 2088 | + | let pairs = dict |
|
| 2089 | + | .borrow() |
|
| 2090 | + | .iter() |
|
| 2091 | + | .map(|(k, v)| Expr::tuple([Expr::from(k.clone()), v.clone()])) |
|
| 2092 | + | .collect::<Vec<_>>(); |
|
| 2093 | + | ||
| 2094 | + | Ok(Expr::tuple(pairs)) |
|
| 2095 | + | } |
|
| 2096 | + | ||
| 2097 | + | /// Merge two dictionaries, with right values overriding left ones. |
|
| 2098 | + | pub fn merge(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 2099 | + | let (left, right) = |
|
| 2100 | + | <(Mut<BTreeMap<Key, Expr>>, Mut<BTreeMap<Key, Expr>>)>::try_from_args(args)?; |
|
| 2101 | + | ||
| 2102 | + | left.borrow_mut() |
|
| 2103 | + | .extend(right.borrow().iter().map(|(k, v)| (k.clone(), v.clone()))); |
|
| 2104 | + | ||
| 2105 | + | Ok(Expr::Dict(Rc::clone(&left))) |
|
| 2106 | + | } |
|
| 2107 | + | ||
| 2034 | 2108 | /// Create a 2D vector. |
|
| 2035 | 2109 | pub fn vec2(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> { |
|
| 2036 | 2110 | let (x, y) = <(f64, f64)>::try_from_args(args)?; |
|
| 2037 | 2111 | Ok(Expr::Vector2D(Vector2D::new(x, y))) |
|
| 2038 | 2112 | } |
| 2505 | 2579 | ); |
|
| 2506 | 2580 | } |
|
| 2507 | 2581 | ||
| 2508 | 2582 | #[test] |
|
| 2509 | 2583 | fn test_dict() { |
|
| 2584 | + | expect( |
|
| 2585 | + | &["(keys {:x 1 :y 2 :z 3})"], |
|
| 2586 | + | Expr::tuple([ |
|
| 2587 | + | (Expr::Atom("x".into())), |
|
| 2588 | + | (Expr::Atom("y".into())), |
|
| 2589 | + | (Expr::Atom("z".into())), |
|
| 2590 | + | ]), |
|
| 2591 | + | ); |
|
| 2592 | + | expect( |
|
| 2593 | + | &["(pairs {:x 1 :y 2})"], |
|
| 2594 | + | Expr::tuple([ |
|
| 2595 | + | Expr::tuple([Expr::Atom("x".into()), Expr::Integer(1)]), |
|
| 2596 | + | Expr::tuple([Expr::Atom("y".into()), Expr::Integer(2)]), |
|
| 2597 | + | ]), |
|
| 2598 | + | ); |
|
| 2599 | + | expect( |
|
| 2600 | + | &["(merge {:x 1 :y 2} {:y 3 :z 4})"], |
|
| 2601 | + | Expr::dict(BTreeMap::from_iter([ |
|
| 2602 | + | (Key::Atom("x".into()), Expr::Integer(1)), |
|
| 2603 | + | (Key::Atom("y".into()), Expr::Integer(3)), |
|
| 2604 | + | (Key::Atom("z".into()), Expr::Integer(4)), |
|
| 2605 | + | ])), |
|
| 2606 | + | ); |
|
| 2607 | + | expect( |
|
| 2608 | + | &["(values {:x 1 :y 2 :z 3})"], |
|
| 2609 | + | Expr::tuple([Expr::Integer(1), Expr::Integer(2), Expr::Integer(3)]), |
|
| 2610 | + | ); |
|
| 2510 | 2611 | expect( |
|
| 2511 | 2612 | &["{:x 1 :y 2 :z 3}"], |
|
| 2512 | - | Expr::dict(HashMap::from_iter([ |
|
| 2613 | + | Expr::dict(BTreeMap::from_iter([ |
|
| 2513 | 2614 | (Key::Atom("x".into()), Expr::Integer(1)), |
|
| 2514 | 2615 | (Key::Atom("y".into()), Expr::Integer(2)), |
|
| 2515 | 2616 | (Key::Atom("z".into()), Expr::Integer(3)), |
|
| 2516 | 2617 | ])), |
|
| 2517 | 2618 | ); |
|
| 2518 | 2619 | expect( |
|
| 2519 | 2620 | &["(dict [:x 1 :y 2 :z (+ 2 1)])"], |
|
| 2520 | - | Expr::dict(HashMap::from_iter([ |
|
| 2621 | + | Expr::dict(BTreeMap::from_iter([ |
|
| 2521 | 2622 | (Key::Atom("x".into()), Expr::Integer(1)), |
|
| 2522 | 2623 | (Key::Atom("y".into()), Expr::Integer(2)), |
|
| 2523 | 2624 | (Key::Atom("z".into()), Expr::Integer(3)), |
|
| 2524 | 2625 | ])), |
|
| 2525 | 2626 | ); |
|
| 2526 | 2627 | expect( |
|
| 2527 | 2628 | &["{:x 1 :y 2 :z (+ 2 1)}"], |
|
| 2528 | - | Expr::dict(HashMap::from_iter([ |
|
| 2629 | + | Expr::dict(BTreeMap::from_iter([ |
|
| 2529 | 2630 | (Key::Atom("x".into()), Expr::Integer(1)), |
|
| 2530 | 2631 | (Key::Atom("y".into()), Expr::Integer(2)), |
|
| 2531 | 2632 | (Key::Atom("z".into()), Expr::Integer(3)), |
|
| 2532 | 2633 | ])), |
|
| 2533 | 2634 | ); |
| 2535 | 2636 | &["(let [d {1 :x 2 :y 3 :z}] (get d 2))"], |
|
| 2536 | 2637 | Expr::Atom("y".into()), |
|
| 2537 | 2638 | ); |
|
| 2538 | 2639 | expect( |
|
| 2539 | 2640 | &["(dict [`x` 1 \"fnord\" 2 41 :a])"], |
|
| 2540 | - | Expr::dict(HashMap::from_iter([ |
|
| 2641 | + | Expr::dict(BTreeMap::from_iter([ |
|
| 2541 | 2642 | (Key::Char('x'), Expr::Integer(1)), |
|
| 2542 | 2643 | (Key::Str("fnord".to_owned()), Expr::Integer(2)), |
|
| 2543 | 2644 | (Key::Integer(41), Expr::Atom("a".into())), |
|
| 2544 | 2645 | ])), |
|
| 2545 | 2646 | ); |
|
| 2546 | - | expect(&["(dict)"], Expr::dict(HashMap::new())); |
|
| 2547 | - | expect(&["(dict [])"], Expr::dict(HashMap::new())); |
|
| 2647 | + | expect(&["(dict)"], Expr::dict(BTreeMap::new())); |
|
| 2648 | + | expect(&["(dict [])"], Expr::dict(BTreeMap::new())); |
|
| 2548 | 2649 | expect_err(&["(dict [:x])"], Error::ExpectedValue("any")); |
|
| 2549 | 2650 | expect_err( |
|
| 2550 | 2651 | &["(dict :who)"], |
|
| 2551 | 2652 | Error::UnexpectedValue(Expr::Atom("who".into())), |
|
| 2552 | 2653 | ); |
ombre/src/lang/parser.rs
+5 -5
| 1 | 1 | //! Parser. |
|
| 2 | 2 | use std::cell::RefCell; |
|
| 3 | - | use std::collections::HashMap; |
|
| 3 | + | use std::collections::BTreeMap; |
|
| 4 | 4 | use std::fmt; |
|
| 5 | 5 | use std::iter::Peekable; |
|
| 6 | 6 | use std::ops::Deref; |
|
| 7 | 7 | use std::rc::Rc; |
|
| 8 | 8 | use std::result; |
| 161 | 161 | ||
| 162 | 162 | fn parse_dict(&mut self) -> Result<Expr> { |
|
| 163 | 163 | self.next_if(|t| t == &Token::LBrace)?; |
|
| 164 | 164 | let mut exprs = self.parse_until(|t| t == &Token::RBrace)?.into_iter(); |
|
| 165 | 165 | self.next_if(|t| t == &Token::RBrace)?; |
|
| 166 | - | let mut dict = HashMap::new(); |
|
| 166 | + | let mut dict = BTreeMap::new(); |
|
| 167 | 167 | ||
| 168 | 168 | while let Some(e) = exprs.next() { |
|
| 169 | 169 | let k = match Key::try_from(e) { |
|
| 170 | 170 | Ok(k) => k, |
|
| 171 | 171 | Err(e) => return Err(Error::InvalidDictKey(e)), |
| 334 | 334 | ); |
|
| 335 | 335 | } |
|
| 336 | 336 | ||
| 337 | 337 | #[test] |
|
| 338 | 338 | fn test_parse_dict() { |
|
| 339 | - | ok("{}", &[Expr::dict(HashMap::default())]); |
|
| 339 | + | ok("{}", &[Expr::dict(BTreeMap::default())]); |
|
| 340 | 340 | ok( |
|
| 341 | 341 | "{:x 32 :y 64 :z 128}", |
|
| 342 | - | &[Expr::dict(HashMap::from_iter([ |
|
| 342 | + | &[Expr::dict(BTreeMap::from_iter([ |
|
| 343 | 343 | (Key::Atom("x".into()), Expr::Integer(32)), |
|
| 344 | 344 | (Key::Atom("y".into()), Expr::Integer(64)), |
|
| 345 | 345 | (Key::Atom("z".into()), Expr::Integer(128)), |
|
| 346 | 346 | ]))], |
|
| 347 | 347 | ); |
|
| 348 | 348 | ok( |
|
| 349 | 349 | "{1 2}", |
|
| 350 | - | &[Expr::dict(HashMap::from_iter([( |
|
| 350 | + | &[Expr::dict(BTreeMap::from_iter([( |
|
| 351 | 351 | Key::Integer(1), |
|
| 352 | 352 | Expr::Integer(2), |
|
| 353 | 353 | )]))], |
|
| 354 | 354 | ); |
|
| 355 | 355 | err("{:x}"); |
ombre/tests/basic.om
+23 -3
| 41 | 41 | ;; Test dictionary operations |
|
| 42 | 42 | (assert (eq? (dict) {})) |
|
| 43 | 43 | (assert (eq? (dict []) {})) |
|
| 44 | 44 | (assert (eq? (dict [:x 1 :y 2 :z (+ 2 1)]) {:x 1 :y 2 :z 3})) |
|
| 45 | 45 | (assert (eq? (let [d {1 :x 2 :y 3 :z}] (get d 2)) :y)) |
|
| 46 | - | ||
| 46 | + | (assert (eq? (keys {}) [])) |
|
| 47 | + | (assert (eq? (keys {:x 1 :y 2}) [:x :y])) |
|
| 48 | + | (assert (eq? (values {}) [])) |
|
| 49 | + | (assert (eq? (values {:x 1 :y 2}) [1 2])) |
|
| 50 | + | (assert (eq? (pairs {}) [])) |
|
| 51 | + | (assert (eq? (pairs {:x 1 :y 2}) [[:x 1] [:y 2]])) |
|
| 52 | + | (assert (eq? (merge {:x 1 :y 2} {:y 3 :z 4}) {:x 1 :y 3 :z 4})) |
|
| 53 | + | (assert (eq? (merge {:a 1} {:b 2}) {:a 1 :b 2})) |
|
| 54 | + | (assert (eq? (merge {} {:x 1}) {:x 1})) |
|
| 55 | + | ||
| 56 | + | ;; Test dictionary mutation |
|
| 47 | 57 | (do |
|
| 48 | 58 | (def d {:x 1 :y 2 :z 3}) |
|
| 49 | 59 | (assert (eq? (get d :x) 1)) |
|
| 50 | 60 | (assert (eq? (get d :y) 2)) |
|
| 51 | 61 | (assert (eq? (get d :z) 3)) |
|
| 52 | 62 | (assert (eq? (get d :w) nil)) |
|
| 53 | 63 | (assert (eq? (put d :w 4) nil)) |
|
| 54 | 64 | (assert (eq? (get d :w) 4)) |
|
| 55 | 65 | (assert (eq? (put d :w 5) 4)) |
|
| 56 | - | (assert (eq? (get d :w) 5))) |
|
| 66 | + | (assert (eq? (get d :w) 5)) |
|
| 67 | + | (assert (eq? (keys d) [:w :x :y :z])) |
|
| 68 | + | (assert (eq? (values d) [5 1 2 3]))) |
|
| 69 | + | ||
| 70 | + | ;; Test dictionary merging |
|
| 71 | + | (do |
|
| 72 | + | (def a {:x 1 :y 2}) |
|
| 73 | + | (def b {:x 5 :z 4}) |
|
| 74 | + | (merge a b) |
|
| 75 | + | (assert (eq? a {:x 5 :y 2 :z 4})) |
|
| 76 | + | (assert (eq? b {:x 5 :z 4}))) |
|
| 57 | 77 | ||
| 58 | 78 | ;; Test boolean operations |
|
| 59 | 79 | (assert true) |
|
| 60 | 80 | (assert (not false)) |
|
| 61 | 81 | (assert (and true true)) |
| 142 | 162 | (assert (eq? (range 17 0 -4) [17 13 9 5 1]) "(range 17 0 -4)") |
|
| 143 | 163 | (assert (eq? (length (range 10)) 10) "(range 10)") |
|
| 144 | 164 | (assert (eq? (length (range -10)) 0) "(range -10)") |
|
| 145 | 165 | (assert (eq? (length (range 1 10)) 9) "(range 1 10)") |
|
| 146 | 166 | ||
| 147 | - | ; vim: filetype=lisp |
|
| 167 | + | ; vim: filetype=clojure |