diff --git a/src/main.rs b/src/main.rs index f7b896c..e467b2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -502,6 +502,7 @@ type Matches<'src> = HashMap; // DONE?: there. can. be. at most. one. match. // i'm happy that this is faster, but it might be worth going back to the per-variable thing +#[must_use] pub fn matches<'src>(vars: &[Symbol], lhs: &Sexp, expr: &'src Sexp) -> Option> { match (lhs, expr) { (Sexp::Atom(a), Sexp::Atom(b)) => { @@ -526,13 +527,14 @@ pub fn matches<'src>(vars: &[Symbol], lhs: &Sexp, expr: &'src Sexp) -> Option None, (Sexp::List(xs), Sexp::List(ys)) => { - if xs.len() == ys.len() { + if xs == ys { + Some(HashMap::with_capacity(0)) + } else if xs.len() == ys.len() { xs.iter() .zip(ys) .map(|(lhs, expr)| matches(vars, lhs, expr)) .reduce(|a, b| match (a, b) { - (None, _) => None, - (_, None) => None, + (None, _) | (_, None) => None, (Some(a), Some(b)) => merge_matches(vars, a, b), }) .unwrap_or(None)