about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/5/construct.c
diff options
context:
space:
mode:
Diffstat (limited to 'usth/ICT2.1/labwork/5/construct.c')
-rw-r--r--usth/ICT2.1/labwork/5/construct.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/usth/ICT2.1/labwork/5/construct.c b/usth/ICT2.1/labwork/5/construct.c
new file mode 100644
index 0000000..235f900
--- /dev/null
+++ b/usth/ICT2.1/labwork/5/construct.c
@@ -0,0 +1,27 @@
+/*
+ * Lisp construct implementation.
+ * Copyright (C) 2019,  Nguyễn Gia Phong
+ * This software is licenced under a CC BY-SA 4.0 license
+ */
+
+#include <stdlib.h>
+
+#include "construct.h"
+
+construct *cons(void *first, construct *rest)
+{
+	construct *list = malloc(sizeof(construct));
+	list->car = first;
+	list->cdr = rest;
+	return list;
+}
+
+void *car(construct *list)
+{
+	return list->car;
+}
+
+construct *cdr(construct *list)
+{
+	return list->cdr;
+}