diff --git a/src/main.rs b/src/main.rs index 720c13a..33971a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -926,7 +926,9 @@ impl<'src> SpecialForm<'src> for Unquote<'src> { match sexp { Sexp::Atom(_) => None, Sexp::List(xs) => match &xs[..] { - [Sexp::Atom(unquote), expr] if *unquote == *UNQUOTE => Some(Self(expr)), + [Sexp::Atom(unquote), expr] if *unquote == *UNQUOTE && is_all_conses(expr) => { + Some(Self(expr)) + } _ => None, }, } @@ -939,7 +941,22 @@ impl<'src> SpecialForm<'src> for Unquote<'src> { } } -fn deconsify(sexp: &Sexp) -> Sexp { +#[must_use] +pub fn is_all_conses(expr: &Sexp) -> bool { + match expr { + Sexp::Atom(_) => true, + Sexp::List(xs) => match &xs[..] { + [Sexp::Atom(cons), car, cdr] if *cons == *CONS => { + is_all_conses(car) && is_all_conses(cdr) + } + [] => true, + _ => false, + }, + } +} + +#[must_use] +pub fn deconsify(sexp: &Sexp) -> Sexp { match sexp { Sexp::Atom(at) => Sexp::Atom(*at), Sexp::List(xs) => match &xs[..] {