+#ifndef __LISTS_H
+#define __LISTS_H
+
+#include <stdbool.h>
+
+typedef int listElt;
+
+typedef struct {
+ listElt car;
+ void* cdr; /* cons ** cdr */
+} cons;
+
+typedef cons** list;
+
+list getNil () {
+ static cons nil1;
+ static cons * nil2 = &nil1;
+ return &nil2;
+}
+
+bool isNil (list c) {
+ return getNil () == c;
+}
+
+listElt car(list l) {
+ if (isNil(l)) {
+ printf("Called car of NIL!\n");
+ fsync(0);
+ exit(-1);
+ }
+ return (*l)->car;
+}
+
+list cdr (list l) {
+ if (isNil(l)) {
+ printf("Called cdr of NIL!\n");
+ fsync(0);
+ exit(-1);
+ }
+ list rt = (list) (*l)->cdr;
+ return rt;
+}
+
+listElt elt (list l, int eltnum) {
+ return (eltnum == 0) ? car(l) : elt (cdr(l), eltnum - 1);
+}
+
+int len (list l) {
+ if (isNil(l)) return 0;
+ return len(cdr(l));
+}
+
+list doCons (int car, list cdr, cons * newCons) {
+ newCons->cdr = (void*) cdr;
+ newCons->car = car;
+}
+
+#endif