20 extern Cell*
const nil;
28 return new IntCell(i);
37 return new DoubleCell(d);
46 return new SymbolCell(s);
54 inline Cell*
cons(Cell*
const my_car, Cell*
const my_cdr)
56 return new ConsCell(my_car, my_cdr);
64 inline Cell*
lambda(Cell*
const my_formals, Cell*
const my_body)
66 return new ProcedureCell(my_formals, my_body);
73 inline bool nullp(Cell*
const c)
82 inline bool listp(Cell*
const c)
84 return nullp(c) || c->is_cons();
93 return !
nullp(c) && c->is_procedure();
100 inline bool intp(Cell*
const c)
102 return !
nullp(c) && c->is_int();
111 return !
nullp(c) && c->is_double();
120 return !
nullp(c) && c->is_symbol();
138 return c->get_double();
148 return c->get_symbol();
155 inline Cell*
car(Cell*
const c)
164 inline Cell*
cdr(Cell*
const c)
176 return c->get_formals();
186 return c->get_body();
bool listp(Cell *const c)
Check if c points to a list (i.e., nil or a cons cell).
Definition: cons.hpp:82
Cell * make_int(const int i)
Make an int cell.
Definition: cons.hpp:26
Cell * make_double(const double d)
Make a double cell.
Definition: cons.hpp:35
double get_double(Cell *const c)
Accessor (error if c is not a double cell).
Definition: cons.hpp:136
Cell * make_symbol(const char *const s)
Make a symbol cell.
Definition: cons.hpp:44
int get_int(Cell *const c)
Accessor (error if c is not an int cell).
Definition: cons.hpp:127
string get_symbol(Cell *const c)
Retrieve the symbol name as a string (error if c is not a symbol cell).
Definition: cons.hpp:146
bool intp(Cell *const c)
Check if c points to an int cell.
Definition: cons.hpp:100
Cell * cdr(Cell *const c)
Accessor (error if c is not a string cell).
Definition: cons.hpp:164
ostream & operator<<(ostream &os, const Cell &c)
Print the subtree rooted at c, in s-expression notation.
Definition: cons.hpp:194
bool nullp(Cell *const c)
Check if c points to an empty list, i.e., is a null pointer.
Definition: cons.hpp:73
Cell *const nil
The null pointer value.
Cell * get_formals(Cell *const c)
Accessor (error if c is not a procedure cell).
Definition: cons.hpp:174
bool symbolp(Cell *const c)
Check if c points to a symbol cell.
Definition: cons.hpp:118
Cell * get_body(Cell *const c)
Accessor (error if c is not a procedure cell).
Definition: cons.hpp:184
Cell * lambda(Cell *const my_formals, Cell *const my_body)
Make a procedure cell.
Definition: cons.hpp:64
Cell * cons(Cell *const my_car, Cell *const my_cdr)
Make a conspair cell.
Definition: cons.hpp:54
bool procedurep(Cell *const c)
Check if c is a procedure cell.
Definition: cons.hpp:91
Cell * car(Cell *const c)
Accessor (error if c is not a cons cell).
Definition: cons.hpp:155
bool doublep(Cell *const c)
Check if c points to a double cell.
Definition: cons.hpp:109