9 #define lhs(t) (*t)->data.application.expr1
10 #define rhs(t) (*t)->data.application.expr2
11 #define bdy(t) (*t)->data.abstraction.expr
13 void lambda_beta(struct lambda
*binding
, struct lambda
**body
, struct lambda
*target
, struct lambda
*total
)
15 switch((*body
)->which
){
17 if((*body
)->data
.identifier
.binding
== binding
){
23 lambda_beta(binding
, &bdy(body
), target
, total
);
26 lambda_beta(binding
, &lhs(body
), target
, total
);
27 lambda_beta(binding
, &rhs(body
), target
, total
);
32 bool lambda_reduce(struct lambda
**t
, struct lambda
**total
, bool applicative
)
34 if((*t
)->which
== lambda_app
){
36 if(lambda_reduce(&rhs(t
), total
, applicative
))
38 if(lhs(t
)->which
!= lambda_abs
){
39 return lambda_reduce(&lhs(t
), total
, applicative
);
41 if(lhs(t
)->data
.abstraction
.strict
)
42 lambda_reduce(&rhs(t
), total
, true);
44 //In this abstraction we substitute the result with the rhs
45 lambda_print(*total
, *t
);
46 lambda_beta(lhs(t
), &lhs(t
)->data
.abstraction
.expr
, rhs(t
), *total
);
48 struct lambda
*newt
= copy(lhs(t
)->data
.abstraction
.expr
);
55 } else if ((*t
)->which
== lambda_abs
) {
56 return lambda_reduce(&bdy(t
), total
, applicative
);