-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval.c
776 lines (654 loc) · 21.1 KB
/
eval.c
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
#include <ctype.h>
#include <stdlib.h> /*NULL, atof*/
#include <stdio.h> /*?sprintf?*/
#include <string.h>/*strcmp*/
#include "eval.h"
#include "parse.h"
int is_int(char* s){
int result = 0;
char c;
if(*s == '-')
s++;
while(isdigit(c=*s++))
result = 1;
return c ? 0 : result;
}
int is_float(char* s){
int result = 0;
char c;
if(*s == '-')
s++;
while(isdigit(c=*s++))
result = 1;
if(c == '.' && result){
result = 0;
while(isdigit(c=*s++))
result = 1;
if(c) result=0;
}
else result = 0;
return result;
}
void printEvalTree(Tree* tree){
if(tree == NULL){
printf("NULL\n");
return;
}
printf("%s = ", tree->node);
printSexpr(tree->value);
printf("\n");
/*printf("%s left\n", tree->node);*/
if(tree->left == NULL);
/*printf("left is null\n");*/
else
printEvalTree(tree->left);
/*printf("%s right\n", tree->node);*/
if(tree->right == NULL);
/*printf("right is null\n");*/
else
printEvalTree(tree->right);
/*printf("%s done\n", tree->node);*/
}
Sexpr* add(Sexpr* s, Env* env){
Sexpr* operand_result;
Sexpr* operand;
float result;
Sexpr* resultSexpr;
/*printf("\nadd\n");
printSexpr(s);*/
if(s == NULL){
printf("\nadd operation on null Sexpr\n");
return NULL;
}
result = 0.0;
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\nadd function call on null inner which should be '+'\n");
return NULL;
}
operand = operand->next;/*set to first operand*/
while(operand != NULL){
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to add non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result += atof(get_atom(operand_result));
deleteSexpr(operand_result);
operand = operand->next;
}
resultSexpr = newSexpr();
create_atom_from_float(resultSexpr, result);
return resultSexpr;
}
Sexpr* multiply(Sexpr* s, Env* env){
Sexpr* operand_result;
Sexpr* operand;
float result;
Sexpr* resultSexpr;
if(s == NULL){
printf("\nmultiply operation on null Sexpr\n");
return NULL;
}
result = 1.0;
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\nmultiply function call on null inner which should be '*'\n");
return NULL;
}
operand = operand->next;/*set to first operand*/
while(operand != NULL){
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to multiply non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result *= atof(get_atom(operand_result));
deleteSexpr(operand_result);
operand = operand->next;
}
resultSexpr = newSexpr();
create_atom_from_float(resultSexpr, result);
return resultSexpr;
}
Sexpr* subtract(Sexpr* s, Env* env){
Sexpr* operand_result;
Sexpr* operand;
float result;
Sexpr* resultSexpr;
if(s == NULL){
printf("\nsub operation on null Sexpr\n");
return NULL;
}
result = 1.0;
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\nsubtact function call on null inner which should be '-'\n");
return NULL;
}
operand = operand->next;/*set to first operand*/
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to subract non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result = atof(get_atom(operand_result));
deleteSexpr(operand_result);
operand = operand->next;
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to subract non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result -= atof(get_atom(operand_result));
deleteSexpr(operand_result);
resultSexpr = newSexpr();
create_atom_from_float(resultSexpr, result);
return resultSexpr;
}
Sexpr* division(Sexpr* s, Env* env){
Sexpr* operand_result;
Sexpr* operand;
float result;
Sexpr* resultSexpr;
if(s == NULL){
printf("\ndiv operation on null Sexpr\n");
return NULL;
}
result = 1.0;
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\ndivision function call on null inner which should be '-'\n");
return NULL;
}
operand = operand->next;/*set to first operand*/
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to divide non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result = atof(get_atom(operand_result));
deleteSexpr(operand_result);
operand = operand->next;
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to divide non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result /= atof(get_atom(operand_result));
deleteSexpr(operand_result);
resultSexpr = newSexpr();
create_atom_from_float(resultSexpr, result);
return resultSexpr;
}
Sexpr* greaterThan(Sexpr* s, Env* env){
Sexpr* operand_result;
Sexpr* operand;
char* bool;
float result;
float result2;
Sexpr* resultSexpr;
if(s == NULL){
printf("\ngreater than operation on null Sexpr\n");
return NULL;
}
/*eval first, eval second, compare and make result, delete those two evals, return result*/
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\ngreater than function call on null inner which should be '>'\n");
return NULL;
}
operand = operand->next;
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to greater-than compare non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result = atof(get_atom(operand_result));
deleteSexpr(operand_result);
operand = operand->next;
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to greater-than compare non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result2 = atof(get_atom(operand_result));
deleteSexpr(operand_result);
bool = result > result2 ? "True" : "False";
resultSexpr = newSexpr();
/*resultSexpr->atom=(char*)malloc(strlen(operand->atom) + 10);
strcpy(resultSexpr->atom,bool);*/
create_atom(resultSexpr, bool);
return resultSexpr;
}
Sexpr* lessThan(Sexpr* s, Env* env){
Sexpr* operand_result;
Sexpr* operand;
char* bool;
float result;
float result2;
Sexpr* resultSexpr;
if(s == NULL){
printf("\nless than operation on null Sexpr\n");
return NULL;
}
/*eval first, eval second, compare and make result, delete those two evals, return result*/
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\nless than function call on null inner which should be '<'\n");
return NULL;
}
operand = operand->next;
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to less-than compare non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result = atof(get_atom(operand_result));
deleteSexpr(operand_result);
operand = operand->next;
operand_result = eval(operand, env);
if(!is_float(get_atom(operand_result)) && !is_int(get_atom(operand_result))){
printf("\ntrying to greater-than compare non-number '%s'\n", get_atom(operand_result));
deleteSexpr(operand_result);
return NULL;
}
result2 = atof(get_atom(operand_result));
deleteSexpr(operand_result);
bool = result < result2 ? "True" : "False";
resultSexpr = newSexpr();
/*resultSexpr->atom=(char*)malloc(strlen(operand->atom) + 10);
strcpy(resultSexpr->atom,bool);*/
create_atom(resultSexpr, bool);
return resultSexpr;
}
Sexpr* equal(Sexpr* s, Env* env){
Sexpr* operand;
Sexpr* result1;
Sexpr* result2;
Sexpr* resultSexpr;
char* bool;
/*!strcmp(get_atom(op), "+")*/
if(s == NULL){
printf("\nequal operation on null Sexpr\n");
return NULL;
}
/*eval first, eval second, compare and make result, delete those two evals, return result*/
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\nequal function call on null inner which should be 'eq?'\n");
return NULL;
}
operand = operand->next;
if(operand == NULL){
printf("\nequal function with no arguments\n");
return NULL;
}
result1 = eval(operand, env);
operand = operand->next;
if(operand == NULL){
printf("\nequal function with only one argument\n");
deleteSexpr(result1);
return NULL;
}
result2 = eval(operand, env);
if(result1 != NULL && result2 != NULL){
if(get_atom(result1) != NULL && get_atom(result2) != NULL){
bool = !strcmp(get_atom(result1), get_atom(result2)) ? "True" : "False";
}
else if(get_atom(result1) == NULL && get_atom(result2) == NULL){
printf("\ncan only call equal on atoms for now\n");
bool = "False";
}
else bool = "False";/*one is NULL and other is not*/
}
else if(result1 == NULL && result2 == NULL) bool = "True";
else bool = "False";/*one is NULL while other is not*/
deleteSexpr(result1);
deleteSexpr(result2);
resultSexpr = newSexpr();
create_atom(resultSexpr, bool);
return resultSexpr;
}
Sexpr* is_atom(Sexpr* s, Env* env){
Sexpr* operand;
Sexpr* atom;
Sexpr* resultSexpr;
char* bool;
if(s == NULL){
printf("\natom? operation on null Sexpr\n");
return NULL;
}
/*eval first, eval second, compare and make result, delete those two evals, return result*/
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\natom? function call on null inner which should be 'atom?'\n");
return NULL;
}
operand = operand->next;
if(operand == NULL){
printf("\natom? called with NULL argument\n");
return NULL;
}
atom = eval(operand, env);
bool = get_atom(atom) != NULL ? "True" : "False";
deleteSexpr(atom);
resultSexpr = newSexpr();
create_atom(resultSexpr, bool);
return resultSexpr;
}
Sexpr* is_null(Sexpr* s, Env* env){
Sexpr* operand;
Sexpr* atom;
Sexpr* resultSexpr;
char* bool;
if(s == NULL){
printf("\nnull? operation on null Sexpr\n");
return NULL;
}
/*eval first, eval second, compare and make result, delete those two evals, return result*/
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\nnull? function call on null inner which should be 'null?'\n");
return NULL;
}
operand = operand->next;
if(operand == NULL){
bool = "True";
}
atom = eval(operand, env);
bool = atom == NULL ? "True" : "False";
deleteSexpr(atom);
resultSexpr = newSexpr();
create_atom(resultSexpr, bool);
return resultSexpr;
}
Sexpr* car(Sexpr* s, Env* env){
/*
eval the argument, set to var, copy the first member of that thing, delete that eval result, return that copied new member
*/
Sexpr* operand;
Sexpr* getCarFromHere;
Sexpr* resultSexpr;
if(s == NULL){
printf("\ncar operation on null Sexpr\n");
return NULL;
}
/*eval first, eval second, compare and make result, delete those two evals, return result*/
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\ncar function call on null inner which should be 'car'\n");
return NULL;
}
operand = operand->next;
if(operand == NULL){
printf("\ntried to car a null sexpr\n");
return NULL;
}
getCarFromHere = eval(operand, env);
resultSexpr = copy_sexpr(get_inner(getCarFromHere));
deleteSexpr(getCarFromHere);
return resultSexpr;
}
Sexpr* cdr(Sexpr* s, Env* env){
/*
eval the argument, set to var, set its inner first to its inner second, delete that first, return that new thing
*/
Sexpr* operand;
Sexpr* removedCdr;
Sexpr* resultSexpr;
if(s == NULL){
printf("\ncdr operation on null Sexpr\n");
return NULL;
}
/*eval first, eval second, compare and make result, delete those two evals, return result*/
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\ncdr function call on null inner which should be 'cdr'\n");
return NULL;
}
operand = operand->next;
if(operand == NULL){
printf("\ntried to cdr a null sexpr\n");
return NULL;
}
resultSexpr = eval(operand, env);
printf("\nresultSexpr first time in cdr\n");
printSexpr(resultSexpr);
removedCdr = get_inner(resultSexpr);
resultSexpr->inner->next = get_inner(resultSexpr)->next;
removedCdr->next = NULL;
deleteSexpr(removedCdr);
return resultSexpr;
}
Sexpr* cond(Sexpr* s, Env* env){
Sexpr* operand;
Sexpr* clause;
Sexpr* predicate;
Sexpr* predicate_value;
Sexpr* expression;
Sexpr* expression_result;
if(s == NULL){
printf("\ncond operation on null Sexpr\n");
return NULL;
}
operand = get_inner(s);/*first inner is the operation*/
if(operand == NULL){
printf("\ncond function call on null inner which should be 'cond'\n");
return NULL;
}
/*while next not null, check if that one predicate evals to true then eval it's value*/
clause = operand->next;
while(clause != NULL){
predicate = get_inner(clause);
if(predicate == NULL){
printf("\nNULL predicate in cond operation\n");
return NULL;
}
predicate_value = eval(predicate, env);
/*if predval == true then return its evaled expression (no copy, just return that eval since that's new anyway)*/
if(get_atom(predicate_value) != NULL && (!strcmp(get_atom(predicate_value), "True") || !strcmp(get_atom(predicate_value), "else"))){
deleteSexpr(predicate_value);
expression = predicate->next;
expression_result = NULL;
while(expression != NULL){
deleteSexpr(expression_result);
expression_result = eval(expression, env);
expression = expression->next;
}
return expression_result;
}
deleteSexpr(predicate_value);
clause = clause->next;
}
printf("\ncond operation with no predicates evaluating to true, returning NULL\n");
return NULL;
}
Sexpr* cons(Sexpr* s, Env* env){
Sexpr* operator;
Sexpr* first_eval;
Sexpr* second_eval;
Sexpr* result_sexpr;
if(s == NULL){
printf("\ncons operation on null Sexpr\n");
return NULL;
}
operator = get_inner(s);/*first inner is the operation*/
if(operator == NULL){
printf("\ncons function call on null inner which should be 'cons'\n");
return NULL;
}
first_eval = eval(operator->next, env);
/*printf("\nfirst eval:");
printSexpr(first_eval);*/
second_eval = eval(operator->next->next, env);
/*printf("\nsecond eval:");
printSexpr(second_eval);
*/
result_sexpr = newSexpr();
create_inner(result_sexpr);
result_sexpr->inner->next = first_eval;
first_eval->next = get_inner(second_eval);
second_eval->inner->next = NULL;
deleteSexpr(second_eval);
return result_sexpr;
/*eval first, eval second.
make new sexpr, set first inner to first evaled, set first evaled's next to first inner of second evaled
make second outer evaled's inner point away to null, delete second outer evaled
*/
}
/*each call to eval means a new sexpr, so delete after it gets used*/
/*if sexpr isn't one passed in or the one to be returned, make sure it's deleted*/
/*don't delete the sexpr passed into the eval func (responsibility of outer)*/
/*all return values from eval should be assigned to a variable, not passed directly into a func, so can be deleted*/
/*don't directly return an input, to outer it should be considered different (i.e. outer could delete sexpr from an eval while not touching its argument)*/
Sexpr* eval(Sexpr* s, Env* env){
Sexpr* op;
Sexpr* lambda_arg_name;
Sexpr* lambda_arg_value;
Sexpr* lambda_sexpr;
Sexpr* beginSexpr;
Sexpr* beginSexprValue;
Sexpr* if_sexpr;
Env* innerEnv;
Sexpr* result_sexpr;
if(s == NULL){
printf("\neval on NULL\n");
return NULL;
}
if(get_atom(s) != NULL){
if(is_int(get_atom(s)) || is_float(get_atom(s)))
return copy_sexpr(s);/*may have to make this a copy of s, since outer should be deleting it*/
else if(!strcmp(get_atom(s), "True") || !strcmp(get_atom(s), "False") || !strcmp(get_atom(s), "else")){
return copy_sexpr(s);
}
else{
return eval(findEnv(env, get_atom(s)), env->inner) ;/*?findEnv returns a copy?*/
}
}
/*TODO NULL checks!*/
op = get_inner(s);
if(get_atom(get_inner(s)) != NULL){
if(!strcmp(get_atom(op), "+"))
return add(s, env);
else if(!strcmp(get_atom(op), "-"))
return subtract(s, env);
else if(!strcmp(get_atom(op), "*"))
return multiply(s, env);
else if(!strcmp(get_atom(op), "/"))
return division(s, env);
else if(!strcmp(get_atom(op), ">"))
return greaterThan(s, env);
else if(!strcmp(get_atom(op), "<"))
return lessThan(s, env);
else if(!strcmp(get_atom(op), "eq?"))
return equal(s, env);
/*else if(get_atom(op) != NULL && !strcmp(get_atom(op), "="))
return equal(s, env);*/
else if(!strcmp(get_atom(op), "atom?"))
return is_atom(s, env);
else if(!strcmp(get_atom(op), "null?"))
return is_null(s, env);
else if(!strcmp(get_atom(op), "car"))
return car(s, env);
else if(!strcmp(get_atom(op), "cdr"))
return cdr(s, env);
else if(!strcmp(get_atom(op), "cond"))
return cond(s, env);
else if(!strcmp(get_atom(op), "cons"))
return cons(s, env);
else if(!strcmp(get_atom(op), "quote"))
return copy_sexpr(op->next);
else if(!strcmp(get_atom(op), "define")){/*only sets for current inner env, so could have another with a different value in outer env*/
insertEnv(env, get_atom(op->next), op->next->next);
}
else if(!strcmp(get_atom(op), "set!")){/*set value for any environment, so set with inner and will find in outer and update that*/
setEnv(env, get_atom(op->next), op->next->next);
}
else if(!strcmp(get_atom(op), "begin")){
beginSexpr = op->next;
beginSexprValue = NULL;
while(beginSexpr){
deleteSexpr(beginSexprValue);
beginSexprValue = eval(beginSexpr, env);
beginSexpr = beginSexpr->next;
}
return beginSexprValue;
}
else if(!strcmp(get_atom(op), "if")){
if_sexpr = eval(op->next, env);
if(if_sexpr != NULL && get_atom(if_sexpr) != NULL && !strcmp(get_atom(if_sexpr), "True")){
deleteSexpr(if_sexpr);
return eval(op->next->next, env);
}
else{
deleteSexpr(if_sexpr);
return eval(op->next->next->next, env);
}
}
else if(!strcmp(get_atom(op), "lambda")){
return s;
}
else{/*assume the first thing is a lambda expression*/
/*
((lambda (a b) (+ a b)) 5 6)
s->inner
sexpr with atom='HEAD'
s->inner->atom = "HEAD"
s->inner->next
sexpr (lambda (a b) (+ a b))
s->inner->next->inner
sexpr with atom ="lambda"
s->inner->next->inner->atom = "HEAD"
s->inner->next->inner->next->atom = "lambda"
s->inner->next->inner->next->next
sexpr with arg names
s->inner->next->inner->next->next->inner
sexpr of arg names (a b)
s->inner->next->inner->next->next->inner->atom
"HEAD" of arg name sexpr
s->inner->next->inner->next->next->inner->next->atom
"a" arg name
s->inner->next->inner->next->next->inner->next->next->atom
"b" arg name
s->inner->next->inner->next->next->next
sexpr of thing to eval
s->inner->next->inner->next->next->next->inner
inner sexpr of thing to eval
s->inner->next->inner->next->next->next->inner->atom
"HEAD" of sexpr to eval
s->inner->next->inner->next->next->next->inner->next->atom
"+" operator
s->inner->next->next->atom
"5"
*/
/*make a new inner env to eval*/
lambda_sexpr = eval(s->inner->next, env);
/*if(lambda_sexpr->inner->next->atom == NULL || strcmp(lambda_sexpr->inner->next->atom, "lambda"))
printf("\nnot lambda as expected?\n");
else
printf("\nlambda as expected\n");*/
innerEnv = newEnv(env);
lambda_arg_name = lambda_sexpr->inner->next->next->inner->next;
lambda_arg_value = s->inner->next->next;
while(lambda_arg_name && lambda_arg_value){
insertEnv(innerEnv, get_atom(lambda_arg_name), lambda_arg_value);
lambda_arg_name = lambda_arg_name->next;
lambda_arg_value = lambda_arg_value->next;
}
return eval(lambda_sexpr->inner->next->next->next, innerEnv);
/*deleteSexpr(lambda_sexpr);
return result_sexpr;*/
}
}
return NULL;
}