-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.hpp
executable file
·174 lines (141 loc) · 4.95 KB
/
functions.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#ifndef FUNCTIONS_HPP
#define FUNCTIONS_HPP
#include <stdexcept>
#include "Cell.hpp"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
/// Helpers
/**
* \brief Since most of the functions take only one argument, a small helper for
* better reuse of code is provided
*/
Cell* single_argument_eval(const SymbolCell* func, Cell* args) throw (runtime_error);
////////////////////////////////////////////////////////////////////////////////
/// Actual implementations of *_func functions
/**
* \brief Implements the ceiling function, using cmath for convenience
* \param args expects a single ConsCell with DoubleCell as car
*/
Cell* ceiling_func(const FunctionCell* func, Cell* args);
/**
* \brief Implements the floor function, using cmath for convenience
* \param Cell*args expects a single ConsCell with DoubleCell as car
*/
Cell* floor_func(const FunctionCell* func, Cell* args);
/**
* \brief Prevents eval to evaluate the s-expression.
*/
Cell* quote_func(const FunctionCell* func, Cell* args) throw (runtime_error);
/**
* \brief Creates a ConsPair with car and cdr similar to those of LISP
* \param args expects a cons list of size 2 containing the car and then cdr in
* that order.
*/
Cell* cons_func(const FunctionCell* func, Cell* args) throw (runtime_error);
/**
* \brief Exposes car from cons.hpp, also evaluates sub-trees
* \param Cell* expects a single ConsCell
*/
Cell* car_func(const FunctionCell* func, Cell* args);
/**
* \brief Exposes cdr from cons.hpp, also evaluates sub-trees
* \param Cell* expects a single ConsCell
*/
Cell* cdr_func(const FunctionCell* func, Cell* args);
/**
* \brief Exposes intp from cons.hpp, also evaluates sub-trees
* \param Cell* expects a single ConsCell
* \return an IntCell containing 0 or 1 indicating true or false
*/
Cell* intp_func(const FunctionCell* func, Cell* args);
/**
* \brief Exposes doublep from cons.hpp, also evaluates sub-trees
* \param Cell* expects a single ConsCell
* \return an IntCell containing 0 or 1 indicating true or false
*/
Cell* doublep_func(const FunctionCell* func, Cell* args);
/**
* \brief Exposes symbolp from cons.hpp, also evaluates sub-trees
* \param Cell* expects a single ConsCell
* \return an IntCell containing 0 or 1 indicating true or false
*/
Cell* symbolp_func(const FunctionCell* func, Cell* args);
/**
* \brief Exposes nullp from cons.hpp, also evaluates sub-trees
* \param Cell* expects a single ConsCell
* \return an IntCell containing 0 or 1 indicating true or false
*/
Cell* nullp_func(const FunctionCell* func, Cell* args);
/**
* \brief Exposes listp from cons.hpp, also evaluates sub-trees
* \param Cell* expects a single ConsCell
* \return an IntCell containing 0 or 1 indicating true or false
*/
Cell* listp_func(const FunctionCell* func, Cell* args);
/**
* \brief If-then branching in form of a callable function. Evaluates only relevant
sub-trees. <b>Special Cow Feature!</b>
* \param Cell* expects a ConsCell with two or three arguments
*/
Cell* if_func(const FunctionCell* func, Cell* args);
/**
* \brief Defines a variable by putting a new definition into the
* definitions map table
*/
Cell* define_func(const FunctionCell* func, Cell* args);
/**
* \brief Compares a variable number of numbers if they are smaller
* than the number on their right side
*/
Cell* less_than_func(const FunctionCell* func, Cell* args);
/**
* \brief Negates argument returning boolean in c style (0 and 1)
*/
Cell* not_func(const FunctionCell* func, Cell* args);
/**
* \brief Printing out evaluated argument
* \return nil Always returns nil
*/
Cell* print_func(const FunctionCell* func, Cell* args);
/**
* \brief Exposed eval from cons.hpp
*/
Cell* eval_func(const FunctionCell* func, Cell* args);
/**
* \brief Creates procedure cell, after doing security checks
*/
Cell* lambda_func(const FunctionCell* func, Cell* args);
/**
* \brief Calls apply on a user defined procedure, created with lambda
*/
Cell* apply_func(const FunctionCell* func, Cell* args);
/**
* \brief Syntactic sugar to add local variables more similar to c
*/
Cell* let_func(const FunctionCell* func, Cell* args);
/**
* \brief used for random variables, takes the range of random values as a range
*/
Cell* rand_func(const FunctionCell* func, Cell* args);
/**
* \brief converts any Cell type to symbol type using print method
*/
Cell* str_func(const FunctionCell* func, Cell* args);
/**
* \brief substring for symbol cells, takes symbol and a range (start
* and end of substr)
*/
Cell* substr_func(const FunctionCell* func, Cell* args);
/**
* \brief appends symbols, takes two symbols
*/
Cell* appstr_func(const FunctionCell* func, Cell* args);
/**
* \brief parses s-expression inside a symbol cell and evaluates it
*/
Cell* parse_func(const FunctionCell* func, Cell* args);
/**
* \brief parses s-expression inside a symbol cell and evaluates it
*/
Cell* parse_eval_func(const FunctionCell* func, Cell* args);
#endif