-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironment.cpp
More file actions
851 lines (711 loc) · 23.2 KB
/
environment.cpp
File metadata and controls
851 lines (711 loc) · 23.2 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
#include "environment.hpp"
#include "semantic_error.hpp"
#include <cassert>
#include <cmath>
#include <complex>
/***********************************************************************
Helper Function(s)
**********************************************************************/
// predicate, the number of args is nargs
bool nargs_equal(const std::vector<Expression> & args, unsigned nargs){
return args.size() == nargs;
}
/***********************************************************************
Each of the functions below have the signature that corresponds to the
typedef'd Procedure function pointer.
**********************************************************************/
// the default procedure always returns an expresison of type None
Expression default_proc(const std::vector<Expression> & args){
args.size(); // make compiler happy we used this parameter
return Expression();
};
Expression add(const std::vector<Expression> & args)
{
// If any argument is complex, the result should be complex
double realSum = 0.0;
double imagSum = 0.0;
bool has_complex = false; // Flag to determine result type
for( auto & a :args){ // Loops over a range of values, whose types are automatically deduced (Like Java)
if(a.isHeadNumber()){
realSum += a.head().asNumber();
}
else if(a.isHeadComplex()){
realSum += a.head().asComplex().real();
imagSum += a.head().asComplex().imag();
has_complex = true;
}
else{
throw SemanticError("Error in call to add, argument not a number");
}
}
if(has_complex){
return Expression(std::complex<double> (realSum, imagSum));
}
else{
return Expression(realSum);
}
};
Expression mul(const std::vector<Expression> & args)
{
// If any argument is complex, the result should be complex
std::complex<double> result = (1.0);
bool has_complex = false; // Flag to determine result type
for( auto & a :args){ // Loops over a range of values, whose types are automatically deduced (Like Java)
if(a.isHeadNumber()){
result *= a.head().asNumber();
}
else if(a.isHeadComplex()){
result *= a.head().asComplex();
has_complex = true;
}
else{
throw SemanticError("Error in call to multiply, argument not a number");
}
}
if(has_complex){
return Expression(result);
}
else{
return Expression(result.real());
}
};
Expression subneg(const std::vector<Expression> & args)
{
// If any argument is complex, the result should be complex
double realResult = 0.0;
double imagResult = 0.0;
bool has_complex = false;
// preconditions
if(nargs_equal(args,1)){
if(args[0].isHeadNumber()){
realResult = -args[0].head().asNumber();
}
else if(args[0].isHeadComplex()){
realResult = -args[0].head().asComplex().real();
imagResult = -args[0].head().asComplex().imag();
has_complex = true;
}
else{
throw SemanticError("Error in call to negate: invalid argument.");
}
}
else if(nargs_equal(args,2)){
if( (args[0].isHeadNumber()) && (args[1].isHeadNumber()) ){
realResult = args[0].head().asNumber() - args[1].head().asNumber();
}
else if( (args[0].isHeadComplex()) || (args[1].isHeadComplex()) ){
realResult = args[0].head().asComplex().real() - args[1].head().asComplex().real();
imagResult = args[0].head().asComplex().imag() - args[1].head().asComplex().imag();
has_complex = true;
}
else{
throw SemanticError("Error in call to subtraction: invalid argument.");
}
}
else{
throw SemanticError("Error in call to subtraction or negation: invalid number of arguments.");
}
if(has_complex){
return Expression(std::complex<double> (realResult, imagResult));
}
else{
return Expression(realResult);
}
};
Expression div(const std::vector<Expression> & args)
{
// If any argument is complex, the result should be complex
std::complex<double> result = (1.0);
bool has_complex = false;
if(nargs_equal(args,1)){
if(args[0].isHeadNumber()){
result = 1/args[0].head().asNumber();
}
else if(args[0].isHeadComplex()){
result = (1.0)/args[0].head().asComplex();
has_complex = true;
}
else{
throw SemanticError("Error in call to division: invalid argument.");
}
}
else if(nargs_equal(args,2)){
if( (args[0].isHeadNumber()) && (args[1].isHeadNumber()) ){
result = args[0].head().asNumber() / args[1].head().asNumber();
}
else if( (args[0].isHeadComplex()) || (args[1].isHeadComplex()) ){
result = args[0].head().asComplex() / args[1].head().asComplex();
has_complex = true;
}
else{
throw SemanticError("Error in call to division: invalid argument.");
}
}
else{
throw SemanticError("Error in call to division: invalid number of arguments.");
}
if(has_complex){
return Expression(result);
}
else{
return Expression(result.real());
}
};
Expression sqrt(const std::vector<Expression> & args)
{
// The square root of a Complex argument or a negative Number argument
std::complex<double> result = (0.0);
bool is_complex = false; // Flag to determine result type
if (nargs_equal(args, 1)) {
if ((args[0].isHeadNumber()) && (args[0].head().asNumber() >= 0)) {
result = std::sqrt(args[0].head().asNumber());
}
else if ((args[0].isHeadComplex()) || (args[0].head().asNumber() < 0)) {
result = std::sqrt(args[0].head().asComplex());
is_complex = true;
}
else {
throw SemanticError("Error in call to square root: invalid argument.");
}
}
else {
throw SemanticError("Error in call to square root: invalid number of arguments.");
}
if (is_complex) {
return Expression(result);
}
else {
return Expression(result.real());
}
};
Expression a_pow_b(const std::vector<Expression> & args)
{
// The result should be of type Number only when both arguments are of type Number
std::complex<double> result = (0.0);
bool is_complex = false; // Flag to determine result type
if (nargs_equal(args, 2)) {
if (args[0].isHeadNumber() && args[1].isHeadNumber()) {
// Store values in local variable for readability
double a = args[0].head().asNumber();
double b = args[1].head().asNumber();
// Check for known cmath error sources before calling function
if ((a >= 0) && (b > 0)) {
result = std::pow(a, b);
}
else {
throw SemanticError("Error in call to a_pow_b: invalid argument.");
}
}
else if ((args[0].isHeadComplex()) || (args[1].isHeadComplex())) {
// Store values in local variable for readability
std::complex<double> a = args[0].head().asComplex();
std::complex<double> b = args[1].head().asComplex();
result = std::pow(a, b);
is_complex = true;
}
else {
throw SemanticError("Error in call to a_pow_b: invalid argument.");
}
}
else {
throw SemanticError("Error in call to a_pow_b: invalid number of arguments.");
}
if (is_complex) {
return Expression(result);
}
else {
return Expression(result.real());
}
};
Expression nat_log(const std::vector<Expression> & args) {
double result = 0;
if (nargs_equal(args, 1)) {
// Check for known cmath error sources before calling function
if (args[0].isHeadNumber() && (args[0].head().asNumber() >= 0)) {
result = std::log(args[0].head().asNumber());
}
else {
throw SemanticError("Error in call to natural log: invalid argument.");
}
}
else {
throw SemanticError("Error in call to natural log: invalid number of arguments.");
}
return Expression(result);
};
Expression sine(const std::vector<Expression> & args) {
double result = 0;
if (nargs_equal(args, 1)) {
if (args[0].isHeadNumber()) {
result = std::sin(args[0].head().asNumber());
}
else { // Might have to limit domain with fmod(args, 2*pi)
throw SemanticError("Error in call to sine: invalid argument.");
}
}
else {
throw SemanticError("Error in call to sine: invalid number of arguments.");
}
return Expression(result);
};
Expression cosine(const std::vector<Expression> & args) {
double result = 0;
if (nargs_equal(args, 1)) {
if (args[0].isHeadNumber()) {
result = std::cos(args[0].head().asNumber());
}
else { // Might have to limit domain with fmod(args, 2*pi)
throw SemanticError("Error in call to cosine: invalid argument.");
}
}
else {
throw SemanticError("Error in call to cosine: invalid number of arguments.");
}
return Expression(result);
};
Expression tangent(const std::vector<Expression> & args) {
double result = 0;
if (nargs_equal(args, 1)) {
if (args[0].isHeadNumber()) {
result = std::tan(args[0].head().asNumber());
}
else { // Might have to limit domain with fmod(args, 2*pi)
throw SemanticError("Error in call to tangent: invalid argument.");
}
}
else {
throw SemanticError("Error in call to tangent: invalid number of arguments.");
}
return Expression(result);
};
Expression get_real_num(const std::vector<Expression> & args)
{
double result = 0.0;
if(nargs_equal(args,1)){
if(args[0].isHeadComplex()){
result = args[0].head().asComplex().real();
}
else{
throw SemanticError("Error in call to get real part: invalid argument.");
}
}
else{
throw SemanticError("Error in call to get real part: invalid number of arguments.");
}
return Expression(result);
};
Expression get_imag_num(const std::vector<Expression> & args)
{
double result = 0.0;
if(nargs_equal(args,1)){
if(args[0].isHeadComplex()){
result = args[0].head().asComplex().imag();
}
else{
throw SemanticError("Error in call to get imaginary part: invalid argument.");
}
}
else{
throw SemanticError("Error in call to get imaginary part: invalid number of arguments.");
}
return Expression(result);
};
Expression get_mag(const std::vector<Expression> & args)
{
// The magnitude (absolute value) of a Complex as a Number
double result = 0.0;
if(nargs_equal(args,1)){
if(args[0].isHeadComplex()){
result = std::abs(args[0].head().asComplex()); // abs is a non-member function of complex
}
else{
throw SemanticError("Error in call to get magnitude: invalid argument.");
}
}
else{
throw SemanticError("Error in call to get magnitude: invalid number of arguments.");
}
return Expression(result);
};
Expression get_arg(const std::vector<Expression> & args)
{
// The argument (angle or phase) of a Complex as a Number in radians
double result = 0.0;
if(nargs_equal(args,1)){
if(args[0].isHeadComplex()){
result = std::arg(args[0].head().asComplex()); // arg is a non-member function of complex
}
else{
throw SemanticError("Error in call to get argument: invalid argument.");
}
}
else{
throw SemanticError("Error in call to get argument: invalid number of arguments.");
}
return Expression(result);
};
Expression get_conj(const std::vector<Expression> & args)
{
// The conjugate of a Complex argument
std::complex<double> result = (0.0);
if(nargs_equal(args,1)){
if(args[0].isHeadComplex()){
result = std::conj(args[0].head().asComplex()); // conj is a non-member function of complex
}
else{
throw SemanticError("Error in call to get conjugate: invalid argument.");
}
}
else{
throw SemanticError("Error in call to get conjugate: invalid number of arguments.");
}
return Expression(result);
};
/*
In our version lists are created using a built-in procedure list, producing an
expression of type List, which may hold an arbitrary-sized, ordered, list of
expressions of any type, including List itself (i.e. it is recursive).
*/
Expression make_list(const std::vector<Expression> & args)
{
// Deep copy new List Type Expression from args
Expression results;
results = Expression(args);
return results;
};
//Add a built-in unary procedure first returning the first expression of the List
//argument. It is a semantic error if the expression is not a List or is empty.
Expression get_first(const std::vector<Expression> & args)
{
Expression result;
if(nargs_equal(args,1)){
if(args[0].isHeadList()){
if(!args[0].asList().empty()){
result = args[0].asList().front();
}
else{
throw SemanticError("Error: argument to first is an empty list");
}
}
else{
throw SemanticError("Error: argument to first is not a list");
}
}
else{
throw SemanticError("Error: invalid number of arguments in call to first");
}
return result;
};
//Add a built-in unary procedure rest returning a list staring at the second element
//of the List argument up to and including the last element. It is a semantic error
//if the expression is not a List or is empty.
Expression get_rest(const std::vector<Expression> & args)
{
std::vector<Expression> result;
if(nargs_equal(args,1)){
if(args[0].isHeadList()){
if(!args[0].asList().empty()){
result = args[0].asList();
result.erase(result.begin());
}
else{
throw SemanticError("Error: argument to rest is an empty list");
}
}
else{
throw SemanticError("Error: argument to rest is not a list");
}
}
else{
throw SemanticError("Error: invalid number of arguments in call to rest");
}
return Expression(result);
};
//Add a built-in unary procedure length returning the number of items in a List
//argument as a Number Expression. It is a semantic error if the expression is not
//a List.
Expression get_length(const std::vector<Expression> & args)
{
double result = 0.0;
if(nargs_equal(args,1)) {
if(args[0].isHeadList()) {
result = args[0].asList().size();
}
else {
throw SemanticError("Error: argument to length is not a list");
}
}
else {
throw SemanticError("Error: invalid number of arguments in call to length");
}
return Expression(result);
};
//Add a built-in binary procedure append that appends the expression of the second
//argument to the first List argument. It is a semantic error if the first argument
//is not a List.
Expression make_append(const std::vector<Expression> & args)
{
std::vector<Expression> result;
if(nargs_equal(args, 2)) {
if(args[0].isHeadList()) {
result = args[0].asList();
result.push_back(args[1]);
}
else {
throw SemanticError("Error: first argument to append is not a list");
}
}
else {
throw SemanticError("Error: invalid number of arguments in call to append");
}
return Expression(result);
};
//Add a built-in binary procedure join that joins each of the List arguments into
//one list. It is a semantic error if any argument is not a List.
Expression make_join(const std::vector<Expression> & args)
{
std::vector<Expression> result;
std::vector<Expression> listArgs;
if(nargs_equal(args, 2)) {
if( (args[0].isHeadList()) && (args[1].isHeadList()) ) {
// Store values in local variable for readability
result = args[0].asList();
listArgs = args[1].asList();
for (auto & exp : listArgs) {
result.push_back(exp);
}
}
else {
throw SemanticError("Error: argument to join is not a list");
}
}
else {
throw SemanticError("Error: invalid number of arguments in call to join");
}
return Expression(result);
};
//Add a built-in procedure range that produces a list of Numbers from a lower-bound
//(the first argument) to an upper-bound (the second argument) in positive increments
//specified by a third argument. It is a semantic error if any argument is not a
//Number, the first argument is not less than the second, or the increment is not
//strictly positive.
Expression make_range(const std::vector<Expression> & args)
{
std::vector<Expression> results;
if(nargs_equal(args,3)) {
if((args[0].isHeadNumber()) && (args[1].isHeadNumber()) && (args[2].isHeadNumber())){
// Store values in local variables for readability
double low = args[0].head().asNumber();
double high = args[1].head().asNumber();
double inc = args[2].head().asNumber();
if(low < high) {
if(inc > 0) {
for (double sum = low; sum <= high; sum += inc) {
results.push_back(Atom(sum));
}
}
else {
throw SemanticError("Error: negative or zero increment in range");
}
}
else {
throw SemanticError("Error: begin greater than end in range");
}
}
else {
throw SemanticError("Error: invalid arguments in range");
}
}
else {
throw SemanticError("Error: invalid number of arguments in range");
}
return Expression(results);
};
/*
* (discrete-plot DATA OPTIONS)
* A binary procedure that takes a List of (x,y) point coordinates and
* a List of (String, Value) pairs specifying one of the following
* plotting options:
*
* "title" - followed by a String representing the title text
* of the plot.
* "abscissa-label" - followed by a String representing the text of the
* abscissa (horizontal, x) label.
* "ordinate-label" - followed by a String representing the text of the
* ordinate (vertical, y) label.
* "text-scale" - positive Number representing the scale factor to
* apply to all text in the plot, defaults to 1.
*
* It returns a List of Graphic objects that render a stem plot of the data.
*/
Expression discrete_plot(const std::vector<Expression> & args)
{
// DATA is the List of Number coordinates (note, they are not required to
// have the "point" object-name), and OPTIONS is a List of Lists, each entry
// being a String Expression followed by an arbitrary Expression
Expression::List result; // List of Lines, Points, and Text Graphic objects
if(nargs_equal(args, 2)){
if( (args[0].isHeadList()) && (args[1].isHeadList()) ){
// Store values in local variable for readability
Expression::List data = args[0].asList();
Expression::List options = args[1].asList();
try {
Expression::List temp = Expression::makeDiscretePlot(data, options);
result = temp;
}
catch (const SemanticError & ex) {
throw ex; // Re-throw error? Idk if this helps or not
//return EXIT_FAILURE;
}
}
else{
throw SemanticError("Error: an argument to discrete-plot is not a list");
}
}
else{
throw SemanticError("Error: invalid number of arguments in call to discrete-plot");
}
return Expression(result);
};
/***********************************************************************
Built-In Symbols
**********************************************************************/
const double PI = std::atan2(0, -1);
const double EXP = std::exp(1);
const std::complex<double> IMAG = std::complex<double>(0.0, 1.0);
/***********************************************************************
Public Methods
**********************************************************************/
Environment::Environment(){
// Default values
isLambda = false;
reset();
}
Environment::Environment(const Environment & env){
// Copy all mapped values using std::map::operator=
envmap = env.envmap;
isLambda = true;
}
bool Environment::is_known(const Atom & sym) const{
if(!sym.isSymbol()) return false;
return envmap.find(sym.asSymbol()) != envmap.end();
}
bool Environment::is_exp(const Atom & sym) const{
if(!sym.isSymbol()) return false;
auto result = envmap.find(sym.asSymbol());
return (result != envmap.end()) && (result->second.type == ExpressionType);
}
Expression Environment::get_exp(const Atom & sym) const{
Expression exp;
if(sym.isSymbol()){
auto result = envmap.find(sym.asSymbol());
if((result != envmap.end()) && (result->second.type == ExpressionType)){
exp = result->second.exp;
}
}
return exp;
}
void Environment::add_exp(const Atom & sym, const Expression & exp){
if(!sym.isSymbol()){
throw SemanticError("Error: Attempt to add non-symbol to environment");
}
// error if overwriting symbol map
if(envmap.find(sym.asSymbol()) != envmap.end()){
if(isLambda){
// Rule exception
EnvResult newValue(ExpressionType, exp);
std::swap(envmap.at(sym.asSymbol()), newValue);
}
else{
throw SemanticError("Error: Attempt to overwrite symbol in environemnt");
}
}
else{
envmap.emplace(sym.asSymbol(), EnvResult(ExpressionType, exp));
}
}
bool Environment::is_proc(const Atom & sym) const{
if(!sym.isSymbol()) return false;
auto result = envmap.find(sym.asSymbol());
return (result != envmap.end()) && (result->second.type == ProcedureType);
}
bool Environment::is_anon_proc(const Atom & sym) const{
if(!sym.isSymbol()) return false;
auto result = envmap.find(sym.asSymbol());
return (result != envmap.end()) && (result->second.exp.isHeadLambda());
}
Procedure Environment::get_proc(const Atom & sym) const{
if(sym.isSymbol()){
auto result = envmap.find(sym.asSymbol());
if((result != envmap.end()) && (result->second.type == ProcedureType)){
return result->second.proc;
}
}
return default_proc;
}
/*
Reset the environment to the default state. First remove all entries and
then re-add the default ones.
*/
void Environment::reset(){
envmap.clear();
// Built-In value of pi
envmap.emplace("pi", EnvResult(ExpressionType, Expression(PI)));
// Built-In value of Euler's Number
envmap.emplace("e", EnvResult(ExpressionType, Expression(EXP)));
// Built-In value of Complex symbol I
envmap.emplace("I", EnvResult(ExpressionType, Expression(IMAG)));
// Procedure: add;
envmap.emplace("+", EnvResult(ProcedureType, add));
// Procedure: subneg;
envmap.emplace("-", EnvResult(ProcedureType, subneg));
// Procedure: mul;
envmap.emplace("*", EnvResult(ProcedureType, mul));
// Procedure: div;
envmap.emplace("/", EnvResult(ProcedureType, div));
// Procedure: sqrt;
envmap.emplace("sqrt", EnvResult(ProcedureType, sqrt));
// Procedure: (^ a b);
envmap.emplace("^", EnvResult(ProcedureType, a_pow_b));
// Procedure: ln;
envmap.emplace("ln", EnvResult(ProcedureType, nat_log));
// Procedure: sin;
envmap.emplace("sin", EnvResult(ProcedureType, sine));
// Procedure: cos;
envmap.emplace("cos", EnvResult(ProcedureType, cosine));
// Procedure: tan;
envmap.emplace("tan", EnvResult(ProcedureType, tangent));
// Procedure: real;
envmap.emplace("real", EnvResult(ProcedureType, get_real_num));
// Procedure: imag;
envmap.emplace("imag", EnvResult(ProcedureType, get_imag_num));
// Procedure: mag;
envmap.emplace("mag", EnvResult(ProcedureType, get_mag));
// Procedure: arg;
envmap.emplace("arg", EnvResult(ProcedureType, get_arg));
// Procedure: conj;
envmap.emplace("conj", EnvResult(ProcedureType, get_conj));
// Procedure: list;
envmap.emplace("list", EnvResult(ProcedureType, make_list));
// Procedure: first;
envmap.emplace("first", EnvResult(ProcedureType, get_first));
// Procedure: rest;
envmap.emplace("rest", EnvResult(ProcedureType, get_rest));
// Procedure: length;
envmap.emplace("length", EnvResult(ProcedureType, get_length));
// Procedure: append;
envmap.emplace("append", EnvResult(ProcedureType, make_append));
// Procedure: join;
envmap.emplace("join", EnvResult(ProcedureType, make_join));
// Procedure: range;
envmap.emplace("range", EnvResult(ProcedureType, make_range));
// Procedure: discrete-plot;
envmap.emplace("discrete-plot", EnvResult(ProcedureType, discrete_plot));
}
bool Environment::operator==(const Environment & env) const noexcept{
// Comparison should work using just the std::map::operator==
return (envmap == env.envmap);
}
bool operator!=(const Environment & left, const Environment & right) noexcept{
return !(left == right);
}