make unquote only apply to well formed cons lists

i wanted to delay it somehow, but this is what i really want (i understand that it's a tradeoff, but...)
This commit is contained in:
mehbark 2023-06-15 00:53:28 -04:00
parent c7354d3c56
commit 4081bb526c

View file

@ -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[..] {