-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimitive_procedures.h
167 lines (111 loc) · 4.07 KB
/
primitive_procedures.h
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
/* Primitive procedures of Scheme */
#ifndef PRIMITIVE_PROCEDURES_H_
#define PRIMITIVE_PROCEDURES_H_
#include <fstream>
#include <cmath>
#include "object.h"
#define NDEBUG
namespace Primitive {
/* Quit */
/* Note: obs should/could be empty */
Object quit(vector<Object>& obs);
/* Reset Evaluator, initialize environment */
/* Note: obs should/could be empty */
Object reset(vector<Object>& obs);
/* Return #t(true) if object is a number */
Object is_number(vector<Object>& obs);
/* Return #t(true) if object is a boolean */
Object is_boolean(vector<Object>& obs);
/* Return #t(true) if object is a integer */
Object is_integer(vector<Object>& obs);
/* Return #t(true) if object is a real */
Object is_real(vector<Object>& obs);
/* Return #t(true) if object is a even integer */
Object is_even(vector<Object>& obs);
/* Return #t(true) if object is a odd integer */
Object is_odd(vector<Object>& obs);
/* Return #t(true) if object is a pair(or list) */
Object is_pair(vector<Object>& obs);
/* Return #t(true) if object is a empty list */
Object is_null(vector<Object>& obs);
/* Return #t(true) if object is a list */
Object is_list(vector<Object>& obs);
/* Primitive operation, note: result's type could be INTEGER or REAL */
/* Return the sum of obs */
Object add(vector<Object>& obs);
/* Return the difference of obs */
Object sub(vector<Object>& obs);
/* Return the product of obs */
Object mul(vector<Object>& obs);
/* Return the quotient of obs */
/* Note: always return real(double), which is different from scheme */
Object div(vector<Object>& obs);
/* Return remainder, it takes two arguments */
Object remainder(vector<Object>& obs);
/* Return quotient */
Object quotient(vector<Object>& obs);
/* Return absolute value */
Object abs(vector<Object>& obs);
/* Return the square of object */
Object square(vector<Object>& obs);
/* Return the sqrt of object */
Object sqrt(vector<Object>& obs);
/* Return true or false as an Object, all obs must be number */
/* Return true if obs[0] < obs[1] < obs[2] < ... < obs[n] */
Object less(vector<Object>& obs);
/* Return true if obs[0] > obs[1] > obs[2] > ... > obs[n] */
Object greater(vector<Object>& obs);
/* Return true if obs[0] == obs[1] == obs[2] == ... == obs[n] */
/* arguments must be numbers */
Object op_equal(vector<Object>& obs);
/* Return true if obs[0] <= obs[1] <= obs[2] <= ... <= obs[n] */
Object lessEqual(vector<Object>& obs);
/* Return true if obs[0] >= obs[1] >= obs[2] >= ... >= obs[n] */
Object greaterEqual(vector<Object>& obs);
/* Return the minimum object of obs */
Object min(vector<Object>& obs);
/* Return the maximum object of obs */
Object max(vector<Object>& obs);
/* Return true if obs[0] equal obs[1] equal obs[2] equal .. equal obs[n]*/
/* arguments could be all types */
Object equal(vector<Object>& obs);
/* Operator! */
Object not(vector<Object>& obs);
/* Operator| */
Object or (vector<Object>& obs);
/* Operator& */
Object and (vector<Object>& obs);
/* Print obs */
Object display(vector<Object>& obs);
/* New line */
Object newline(vector<Object>& obs);
/* Load code from input file and evaluate */
/* Usage: (load "path/name.scm") */
Object load(vector<Object>& obs);
/* Return the pair of obs as an Object */
/* Note: obs.size() must be 2 */
Object make_cons(vector<Object>& obs);
/* Return the list of obs as an Object */
Object make_list(vector<Object>& obs);
/* Return the car of object */
Object car(vector<Object>& obs);
/* Return the cdr of object */
Object cdr(vector<Object>& obs);
/* Return the caar of object */
Object caar(vector<Object>& obs);
/* Return the cadr of object */
Object cadr(vector<Object>& obs);
/* Return the cdar of object */
Object cdar(vector<Object>& obs);
/* Return the cddr of object */
Object cddr(vector<Object>& obs);
/* Append an object or a list to obs[0] */
Object append(vector<Object>& obs);
/* Return length of obs[0] */
Object length(vector<Object>& obs);
/* scheme: map */
Object map(vector<Object>& obs);
/* scheme: for-each */
Object for_each(vector<Object>& obs);
};
#endif