-
Notifications
You must be signed in to change notification settings - Fork 0
/
lisp.h
63 lines (46 loc) · 1.85 KB
/
lisp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include "general.h"
typedef struct lisp lisp;
typedef int atomtype;
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>
// Returns element 'a' - this is not a list, and
// by itself would be printed as e.g. "3", and not "(3)"
lisp *lisp_atom(const atomtype a);
// Returns a list containing the car as 'l1'
// and the cdr as 'l2'- data in 'l1' and 'l2' are reused,
// and not copied. Either 'l1' and/or 'l2' can be NULL
lisp *lisp_cons(const lisp *l1, const lisp *l2);
// Returns the car (1st) component of the list 'l'.
// Does not copy any data.
lisp *lisp_car(const lisp *l);
// Returns the cdr (all but the 1st) component of the list 'l'.
// Does not copy any data.
lisp *lisp_cdr(const lisp *l);
// Returns the data/value stored in the cons 'l'
atomtype lisp_getval(const lisp *l);
// Returns a boolean depending up whether l points to an atom (not a list)
bool lisp_isatomic(const lisp *l);
// Returns a deep copy of the list 'l'
lisp *lisp_copy(const lisp *l);
// Returns number of components in the list.
int lisp_length(const lisp *l);
// Returns stringified version of list
void lisp_tostring(const lisp *l, char *str);
// Clears up all space used
// Double pointer allows function to set 'l' to NULL on success
void lisp_free(lisp **l);
// Builds a new list based on the string 'str'
lisp *lisp_fromstring(const char *str);
// Returns a new list from a set of existing lists.
// A variable number 'n' lists are used.
// Data in existing lists are reused, and not copied.
// You need to understand 'varargs' for this.
lisp *lisp_list(const int n, ...);
// Allow a user defined function 'func' to be applied to
// each atom in the list l.
// The user-defined 'func' is passed a pointer to a cons,
// and will maintain an accumulator of the result.
void lisp_reduce(void (*func)(lisp *l, atomtype *n), lisp *l, atomtype *acc);