cons.hpp

Go to the documentation of this file.
00001 
00009 #ifndef CONS_HPP
00010 #define CONS_HPP
00011 
00012 #include <iostream>
00013 #include "Cell.hpp"
00014 
00015 using namespace std;
00016 
00020 extern Cell* const nil;
00021 
00026 inline Cell* make_int(const int i)
00027 {
00028   return new IntCell(i);
00029 }
00030 
00035 inline Cell* make_double(const double d)
00036 {
00037   return new DoubleCell(d);
00038 }
00039 
00044 inline Cell* make_symbol(const char* const s)
00045 {
00046   return new SymbolCell(s);
00047 }
00048 
00054 inline Cell* cons(Cell* const my_car, Cell* const my_cdr)
00055 {
00056   return new ConsCell(my_car, my_cdr);
00057 }
00058 
00064 inline Cell* lambda(Cell* const my_formals, Cell* const my_body)
00065 {
00066   return new ProcedureCell(my_formals, my_body);
00067 }
00068 
00073 inline bool nullp(Cell* const c)
00074 {
00075   return (c == nil);
00076 }
00077 
00082 inline bool listp(Cell* const c)
00083 {
00084   return nullp(c) || c->is_cons();
00085 }
00086 
00091 inline bool procedurep(Cell* const c)
00092 {
00093   return !nullp(c) && c->is_procedure();
00094 }
00095 
00100 inline bool intp(Cell* const c)
00101 {
00102   return !nullp(c) && c->is_int();
00103 }
00104 
00109 inline bool doublep(Cell* const c)
00110 {
00111   return !nullp(c) && c->is_double();
00112 }
00113 
00118 inline bool symbolp(Cell* const c)
00119 {
00120   return !nullp(c) && c->is_symbol();
00121 }
00122 
00127 inline int get_int(Cell* const c)
00128 {
00129   return c->get_int();
00130 }
00131 
00136 inline double get_double(Cell* const c)
00137 {
00138   return c->get_double();
00139 }
00140 
00146 inline string get_symbol(Cell* const c)
00147 {
00148   return c->get_symbol();
00149 }
00150 
00155 inline Cell* car(Cell* const c)
00156 {
00157   return c->get_car();
00158 }
00159 
00164 inline Cell* cdr(Cell* const c)
00165 {
00166   return c->get_cdr();
00167 }
00168 
00174 inline Cell* get_formals(Cell* const c)
00175 {
00176   return c->get_formals();
00177 }
00178 
00184 inline Cell* get_body(Cell* const c)
00185 {
00186   return c->get_body();
00187 }
00188 
00194 inline ostream& operator<<(ostream& os, const Cell& c)
00195 {
00196   c.print(os);
00197   return os;
00198 }
00199 
00200 #endif // CONS_HPP

Generated on Wed May 7 09:26:26 2008 for a1 by  doxygen 1.5.3