Make nicer primitive functions for car/cdr
If it isn't a CONS, we return NIL instead of failing. This way, we can use it in our general iteration functions. Eventually the actual runtime would use this as well. The macros are mostly for internal use to do assignment etc.
This commit is contained in:
@@ -46,3 +46,19 @@ lisp_t *intern(sys_t *sys, sv_t sv)
|
||||
char *str = sym_table_find(&sys->symtable, sv);
|
||||
return tag_sym(str);
|
||||
}
|
||||
|
||||
lisp_t *car(lisp_t *lsp)
|
||||
{
|
||||
if (!IS_TAG(lsp, CONS))
|
||||
return NIL;
|
||||
else
|
||||
return CAR(lsp);
|
||||
}
|
||||
|
||||
lisp_t *cdr(lisp_t *lsp)
|
||||
{
|
||||
if (!IS_TAG(lsp, CONS))
|
||||
return NIL;
|
||||
else
|
||||
return CDR(lsp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user