~brenns10/funlisp

c7dd544ea773f006d6dbf1cf044309f7aa353025 — Stephen Brennan 2 years ago b1a8754
Implement list builtin
2 files changed, 15 insertions(+), 0 deletions(-)

M scripts/tests/basics.lisp
M src/builtins.c
M scripts/tests/basics.lisp => scripts/tests/basics.lisp +3 -0
@@ 43,4 43,7 @@
(assert-error 'LE_SYNTAX (cond (a b c)))
(assert-error 'LE_SYNTAX (cond 1))

(assert (equal? (list 1 (+ 1 1) (/ 9 3) (* 2 2)) '(1 2 3 4)))
(assert (equal? (list 1 2 list 4) `(1 2 ,list 4)))

; OUTPUT(0)

M src/builtins.c => src/builtins.c +12 -0
@@ 688,6 688,17 @@ static lisp_value *lisp_builtin_cond(
	return lisp_nil_new(rt);
}

static lisp_value *lisp_builtin_list(
		lisp_runtime *rt, lisp_scope *scope, lisp_list *arglist, void *user)
{
	/* args are evaluated */
	(void) rt;
	(void) scope;
	(void) user;
	return (lisp_value*)arglist;
}


void lisp_scope_populate_builtins(lisp_runtime *rt, lisp_scope *scope)
{
	lisp_scope_add_builtin(rt, scope, "eval", lisp_builtin_eval, NULL, 1);


@@ 723,4 734,5 @@ void lisp_scope_populate_builtins(lisp_runtime *rt, lisp_scope *scope)
	lisp_scope_add_builtin(rt, scope, "assert", lisp_builtin_assert, NULL, 1);
	lisp_scope_add_builtin(rt, scope, "assert-error", lisp_builtin_assert_error, NULL, 0);
	lisp_scope_add_builtin(rt, scope, "cond", lisp_builtin_cond, NULL, 0);
	lisp_scope_add_builtin(rt, scope, "list", lisp_builtin_list, NULL, 1);
}