83ab5367a0c74491d8013cd73c49805e7346f332
8 void subst(char *ident
, struct lambda
*t1
, struct lambda
*t2
, struct lambda
*total
)
13 if(strcmp(t1
->data
.identifier
, ident
) == 0){
15 free(t1
->data
.identifier
);
22 if(strcmp(t1
->data
.abstraction
.ident
, ident
) != 0)
23 subst(ident
, t1
->data
.abstraction
.expr
, t2
, total
);
26 subst(ident
, t1
->data
.application
.expr1
, t2
, total
);
27 subst(ident
, t1
->data
.application
.expr2
, t2
, total
);
33 void lambda_reduce(struct lambda
*t
, struct lambda
*total
, int *maxdepth
)
37 struct lambda
*t1
, *t2
;
42 lambda_reduce(t
->data
.abstraction
.expr
, total
, maxdepth
);
45 //If the first argument is an abstraction, we apply
46 t1
= t
->data
.application
.expr1
;
47 t2
= t
->data
.application
.expr2
;
48 if(t1
->which
== lambda_abs
){
49 subst(t1
->data
.abstraction
.ident
, t1
->data
.abstraction
.expr
, t2
, total
);
52 *total
= *t1
->data
.abstraction
.expr
;
53 *t
= *t1
->data
.abstraction
.expr
;
56 lambda_reduce(t
, total
, maxdepth
);