Skip to content

Commit

Permalink
Fix for macro expansion bug and test (#47)
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
shsms authored Nov 11, 2023
2 parents 76b3dc1 + 162a45d commit 29000c2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub(crate) fn funcall<E: Evaluator>(
ref body,
} => eval_lambda::<E>(ctx, params, body, args),
TulispValue::Macro(_) | TulispValue::Defmacro { .. } => {
let expanded = macroexpand(ctx, list!(func.clone(), args.clone())?)?;
let expanded = macroexpand(ctx, list!(func.clone() ,@args.clone())?)?;
eval(ctx, &expanded)
}
_ => Err(
Expand Down
40 changes: 40 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,3 +1029,43 @@ fn test_load() -> Result<(), Error> {

Ok(())
}

#[test]
fn test_macroexpand() -> Result<(), Error> {
let mut ctx = TulispContext::new();
tulisp_assert! {
ctx: ctx,
program: r#"
(defmacro make (alist)
(setq make-args alist)
t)
(eval (list 'make `(,(cons 'a 1) ,(cons 'b 2))))
make-args
"#,
result: r#"'((a . 1) (b . 2))"#,
}

tulisp_assert! {
ctx: ctx,
program: r#"
(macroexpand '(make ((a . 1) (b . 2) (c . 3))))
make-args
"#,
result: r#"'((a . 1) (b . 2) (c . 3))"#,
}

tulisp_assert! {
ctx: ctx,
program: r#"
(make ((a . 1) (b . 2) (c . 3) (d . 4)))
make-args
"#,
result: r#"'((a . 1) (b . 2) (c . 3) (d . 4))"#,
}

Ok(())
}

0 comments on commit 29000c2

Please sign in to comment.