fix append func

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-02-28 09:59:33 -08:00
parent 09e3546ba6
commit 452cb7a654
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
2 changed files with 27 additions and 5 deletions

View file

@ -15,15 +15,19 @@
*/
use crate::segment::{Ctr, Seg};
use crate::sym::{SymTable};
use crate::sym::SymTable;
// Some essential operations below
pub fn append_callback (ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
// if car is a list, append cdr
// otherwise create a list out of all arguments
if let Ctr::Seg(ref s) = *ast.car {
let mut temp = s.clone();
temp.append(ast.cdr.clone());
if let Ctr::Seg(ref list) = *ast.cdr {
list.circuit(&mut |c: &Ctr| -> bool {
temp.append(Box::new(c.clone()));
true
});
} else {
temp.append(Box::new(*ast.cdr.clone()));
}
Ok(Ctr::Seg(temp))
} else {
let mut temp = Seg::new();