00001
00009 #ifndef CONS_HPP
00010 #define CONS_HPP
00011
00012 #include "Cell.hpp"
00013 #include <string>
00014 #include <iostream>
00015
00019 extern Cell* const nil;
00020
00025 inline Cell* make_int(const int i)
00026 {
00027 return new Cell(i);
00028 }
00029
00034 inline Cell* make_double(const double d)
00035 {
00036 return new Cell(d);
00037 }
00038
00043 inline Cell* make_symbol(const char* const s)
00044 {
00045 return new Cell(s);
00046 }
00047
00053 inline Cell* cons(Cell* const my_car, Cell* const my_cdr)
00054 {
00055 return new Cell(my_car, my_cdr);
00056 }
00057
00062 inline bool nullp(Cell* const c)
00063 {
00064 return (c == nil);
00065 }
00066
00071 inline bool listp(Cell* const c)
00072 {
00073 return nullp(c) || c->is_cons();
00074 }
00075
00080 inline bool intp(Cell* const c)
00081 {
00082 return !nullp(c) && c->is_int();
00083 }
00084
00089 inline bool doublep(Cell* const c)
00090 {
00091 return !nullp(c) && c->is_double();
00092 }
00093
00098 inline bool symbolp(Cell* const c)
00099 {
00100 return !nullp(c) && c->is_symbol();
00101 }
00102
00107 inline int get_int(Cell* const c)
00108 {
00109 return c->get_int();
00110 }
00111
00116 inline double get_double(Cell* const c)
00117 {
00118 return c->get_double();
00119 }
00120
00126 inline std::string get_symbol(Cell* const c)
00127 {
00128 return c->get_symbol();
00129 }
00130
00135 inline Cell* car(Cell* const c)
00136 {
00137 return c->get_car();
00138 }
00139
00144 inline Cell* cdr(Cell* const c)
00145 {
00146 return c->get_cdr();
00147 }
00148
00154 inline std::ostream& operator<<(std::ostream& os, const Cell& c)
00155 {
00156 c.print(os);
00157 return os;
00158 }
00159
00160 #endif // CONS_HPP