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 
00063 inline bool nullp(Cell* const c)
00064 {
00065   return (c == nil);
00066 }
00067 
00072 inline bool listp(Cell* const c)
00073 {
00074   return nullp(c) || c->is_cons();
00075 }
00076 
00081 inline bool intp(Cell* const c)
00082 {
00083   return !nullp(c) && c->is_int();
00084 }
00085 
00090 inline bool doublep(Cell* const c)
00091 {
00092   return !nullp(c) && c->is_double();
00093 }
00094 
00099 inline bool symbolp(Cell* const c)
00100 {
00101   return !nullp(c) && c->is_symbol();
00102 }
00103 
00108 inline int get_int(Cell* const c)
00109 {
00110   return c->get_int();
00111 }
00112 
00117 inline double get_double(Cell* const c)
00118 {
00119   return c->get_double();
00120 }
00121 
00127 inline string get_symbol(Cell* const c)
00128 {
00129   return c->get_symbol();
00130 }
00131 
00136 inline Cell* car(Cell* const c)
00137 {
00138   return c->get_car();
00139 }
00140 
00145 inline Cell* cdr(Cell* const c)
00146 {
00147   return c->get_cdr();
00148 }
00149 
00155 inline ostream& operator<<(ostream& os, const Cell& c)
00156 {
00157   c.print(os);
00158   return os;
00159 }
00160 
00161 #endif // CONS_HPP

Generated on Sat Apr 21 00:06:25 2007 for a1 by  doxygen 1.5.1