use tulisp::{Error, TulispContext, TulispObject, list};
fn main() -> Result<(), Error> {
let mut ctx = TulispContext::new();
ctx.eval_string("(defun double (x) (* x 2))")?;
let double = ctx.intern("double");
let result = ctx.funcall(&double, &list!(,TulispObject::from(21))?)?;
println!("(double 21) => {}", result.as_int()?);
let nums: TulispObject = (1..=5).map(TulispObject::from).collect();
let squarer = ctx.eval_string("(lambda (n) (* n n))")?;
let squared = ctx.map(&squarer, &nums)?;
println!("map (lambda (n) (* n n)) {nums} => {squared}");
let plus = ctx.intern("+");
let total = ctx.reduce(&plus, &squared, &TulispObject::from(0))?;
println!("sum of squares => {}", total.as_int()?);
Ok(())
}