diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-16 03:25:45 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-16 03:25:45 +0300 |
commit | 4daf7b149622a16a2271630a19f0833702477a86 (patch) | |
tree | bc09cbc387ab4e551557f94b67c72e7095a07658 /src/sexp | |
parent | fad9bf51e9ecd48473046a5e7bb9b5005893ae89 (diff) | |
download | myslip-4daf7b149622a16a2271630a19f0833702477a86.tar.gz myslip-4daf7b149622a16a2271630a19f0833702477a86.zip |
feat: vector concatenation
Diffstat (limited to 'src/sexp')
-rw-r--r-- | src/sexp/display.rs | 1 | ||||
-rw-r--r-- | src/sexp/mod.rs | 1 | ||||
-rw-r--r-- | src/sexp/step.rs | 21 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/sexp/display.rs b/src/sexp/display.rs index e2f4ffc..ec1b421 100644 --- a/src/sexp/display.rs +++ b/src/sexp/display.rs @@ -28,6 +28,7 @@ impl fmt::Display for SLeaf { RestPat(s) => format!("..{s}"), Quote => "quote".to_string(), Vector => "vector".to_string(), + Concat => "<>".to_string(), Print => "print".to_string(), Let => "let".to_string(), Fun => "fn".to_string(), diff --git a/src/sexp/mod.rs b/src/sexp/mod.rs index aa51811..1a90f52 100644 --- a/src/sexp/mod.rs +++ b/src/sexp/mod.rs @@ -30,6 +30,7 @@ pub enum SLeaf { Or, Not, Xor, + Concat, Quote, Vector, diff --git a/src/sexp/step.rs b/src/sexp/step.rs index 9077401..59b201c 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -441,6 +441,27 @@ impl SExp { }, + // Concatenation + SCons(op, l) if *op == Atom(Concat) => { + let ls = l.parts(); + let firstvec = ls.get(0).unwrap(); + let secondvec = ls.get(1).unwrap(); + let firstvec = match firstvec { + SCons(a, b) if **a == Atom(Vector) => *b.clone(), + t => t.clone(), + }; + let secondvec = match secondvec { + SCons(a, b) if **a == Atom(Vector) => *b.clone(), + t => t.clone(), + }; + let mut res = Atom(Nil); + for exp in firstvec.parts().into_iter().chain(secondvec.parts()).rev() { + res = scons(exp, res); + } + Ok(scons(Vector, res)) + }, + + // Arithmetic |