microScheme
Functions | Variables
cons.hpp File Reference
#include <iostream>
#include "Cell.hpp"

Go to the source code of this file.

Functions

Cell * make_int (const int i)
 Make an int cell. More...
 
Cell * make_double (const double d)
 Make a double cell. More...
 
Cell * make_symbol (const char *const s)
 Make a symbol cell. More...
 
Cell * cons (Cell *const my_car, Cell *const my_cdr)
 Make a conspair cell. More...
 
Cell * lambda (Cell *const my_formals, Cell *const my_body)
 Make a procedure cell. More...
 
bool nullp (Cell *const c)
 Check if c points to an empty list, i.e., is a null pointer. More...
 
bool listp (Cell *const c)
 Check if c points to a list (i.e., nil or a cons cell). More...
 
bool procedurep (Cell *const c)
 Check if c is a procedure cell. More...
 
bool intp (Cell *const c)
 Check if c points to an int cell. More...
 
bool doublep (Cell *const c)
 Check if c points to a double cell. More...
 
bool symbolp (Cell *const c)
 Check if c points to a symbol cell. More...
 
int get_int (Cell *const c)
 Accessor (error if c is not an int cell). More...
 
double get_double (Cell *const c)
 Accessor (error if c is not a double cell). More...
 
string get_symbol (Cell *const c)
 Retrieve the symbol name as a string (error if c is not a symbol cell). More...
 
Cell * car (Cell *const c)
 Accessor (error if c is not a cons cell). More...
 
Cell * cdr (Cell *const c)
 Accessor (error if c is not a string cell). More...
 
Cell * get_formals (Cell *const c)
 Accessor (error if c is not a procedure cell). More...
 
Cell * get_body (Cell *const c)
 Accessor (error if c is not a procedure cell). More...
 
ostream & operator<< (ostream &os, const Cell &c)
 Print the subtree rooted at c, in s-expression notation. More...
 

Variables

Cell *const nil
 The null pointer value. More...
 

Detailed Description

Encapsulates an abstract interface layer for a cons list ADT, without using member functions. Makes no assumptions about what kind of concrete type Cell will be defined to be.

Function Documentation

Cell* car ( Cell *const  c)
inline

Accessor (error if c is not a cons cell).

Returns
The car pointer in the cons cell pointed to by c.

Referenced by separate_parse().

Cell* cdr ( Cell *const  c)
inline

Accessor (error if c is not a string cell).

Returns
The cdr pointer in the cons cell pointed to by c.

Referenced by separate_parse().

Cell* cons ( Cell *const  my_car,
Cell *const  my_cdr 
)
inline

Make a conspair cell.

Parameters
my_carThe initial car pointer to be stored in the new cell.
my_cdrThe initial cdr pointer to be stored in the new cell.

Referenced by separate_parse().

bool doublep ( Cell *const  c)
inline

Check if c points to a double cell.

Returns
True iff c points to a double cell.

References nullp().

Cell* get_body ( Cell *const  c)
inline

Accessor (error if c is not a procedure cell).

Returns
Pointer to the cons list containing the expression defining the body for the function pointed to by c.
double get_double ( Cell *const  c)
inline

Accessor (error if c is not a double cell).

Returns
The value in the double cell pointed to by c.
Cell* get_formals ( Cell *const  c)
inline

Accessor (error if c is not a procedure cell).

Returns
Pointer to the cons list of formal parameters for the function pointed to by c.
int get_int ( Cell *const  c)
inline

Accessor (error if c is not an int cell).

Returns
The value in the int cell pointed to by c.
string get_symbol ( Cell *const  c)
inline

Retrieve the symbol name as a string (error if c is not a symbol cell).

Returns
The symbol name in the symbol cell pointed to by c.
bool intp ( Cell *const  c)
inline

Check if c points to an int cell.

Returns
True iff c points to an int cell.

References nullp().

Cell* lambda ( Cell *const  my_formals,
Cell *const  my_body 
)
inline

Make a procedure cell.

Parameters
my_formalsA list of the procedure's formal parameter names.
my_bodyThe body (an expression) of the procedure.
bool listp ( Cell *const  c)
inline

Check if c points to a list (i.e., nil or a cons cell).

Returns
True iff c points to a list (i.e., nil or a cons cell).

References nullp().

Cell* make_double ( const double  d)
inline

Make a double cell.

Parameters
dThe initial double value to be stored in the new cell.

Referenced by makecell().

Cell* make_int ( const int  i)
inline

Make an int cell.

Parameters
iThe initial int value to be stored in the new cell.

Referenced by makecell().

Cell* make_symbol ( const char *const  s)
inline

Make a symbol cell.

Parameters
sThe initial symbol name to be stored in the new cell.

Referenced by makecell().

bool nullp ( Cell *const  c)
inline

Check if c points to an empty list, i.e., is a null pointer.

Returns
True iff c points to an empty list, i.e., is a null pointer.

References nil.

Referenced by doublep(), intp(), listp(), procedurep(), and symbolp().

ostream& operator<< ( ostream &  os,
const Cell &  c 
)
inline

Print the subtree rooted at c, in s-expression notation.

Parameters
osThe output stream to print to.
cThe root cell of the subtree to be printed.
bool procedurep ( Cell *const  c)
inline

Check if c is a procedure cell.

Returns
True iff c is a procedure cell.

References nullp().

bool symbolp ( Cell *const  c)
inline

Check if c points to a symbol cell.

Returns
True iff c points to a symbol cell.

References nullp().

Variable Documentation

Cell* const nil

The null pointer value.

Referenced by nullp(), and parse_eval_print().