aboutsummaryrefslogtreecommitdiff
path: root/constructor.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-08-21 14:54:57 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-08-21 14:55:54 +0100
commit0f68afd9a040256939ddd082a380bd37b0a3996b (patch)
tree2c59292ca62bfe70a09b7e7efadfcc756b0914c6 /constructor.c
parent742f19886cce986d0d01606b07dd533fbffe2cdd (diff)
downloadalisp-0f68afd9a040256939ddd082a380bd37b0a3996b.tar.gz
alisp-0f68afd9a040256939ddd082a380bd37b0a3996b.tar.bz2
alisp-0f68afd9a040256939ddd082a380bd37b0a3996b.zip
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.
Diffstat (limited to 'constructor.c')
-rw-r--r--constructor.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/constructor.c b/constructor.c
index 9db0330..e0fab52 100644
--- a/constructor.c
+++ b/constructor.c
@@ -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);
+}