From e35522189f5217987bc455d70c3b9056541ef8c6 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sat, 16 Aug 2025 02:04:09 +0300 Subject: feat: type conversion from (Vec/Quote X) -> X and add vec/quote to rest pattern substitutions --- src/sexp/step.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/sexp/step.rs') diff --git a/src/sexp/step.rs b/src/sexp/step.rs index 99925ac..9077401 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -352,9 +352,10 @@ impl SExp { return Ok(SExp::back_to_case(scrutinee.step()?, patarms)); } - let scrutinee = match scrutinee { - SCons(q, v) if *q == Atom(Quote) || *q == Atom(Vector) => *v, - t => t, + let (scrutinee, rest_pat_struct) = match scrutinee { + SCons(q, v) if *q == Atom(Quote) => (*v, Some(Quote)), + SCons(q, v) if *q == Atom(Vector) => (*v, Some(Vector)), + t => (t, None), }; for patarm in patarms { @@ -369,7 +370,14 @@ impl SExp { if let Some(ctx) = scrutinee.matches_pat(&pat) { for (name, value) in ctx { - arm = arm.subst(&name, &value); + arm = match name { + Var(name) => arm.subst(&name, &value), + RestPat(name) => match rest_pat_struct.clone() { + Some(kw) => arm.subst(&name, &scons(kw, value)), + None => arm.subst(&name, &value) + }, + _ => panic!("unreachable") + }; } return Ok(arm); } -- cgit v1.2.3