lambda-calculus/booleans/new.c
2025-01-13 20:36:07 -06:00

82 lines
1.3 KiB
C

#include <debug.h>
#include <memory/smalloc.h>
#include <string/new.h>
#include <string/free.h>
#include <value/lambda/new.h>
#include <expression/variable/new.h>
#include <expression/lambda/new.h>
#include <expression/free.h>
#include "struct.h"
#include "new.h"
struct booleans* new_booleans(void)
{
ENTER;
struct booleans* this = smalloc(sizeof(*this));
struct string* x = new_string(L"x", 1);
struct string* y = new_string(L"y", 1);
{
struct expression* body = new_variable_expression(x);
struct expression* lambda_y = new_lambda_expression(y, body);
struct value* lambda_xy = new_lambda_value(NULL, x, lambda_y);
this->true_value = lambda_xy;
free_expression(lambda_y);
free_expression(body);
}
{
struct expression* body = new_variable_expression(y);
struct expression* lambda_y = new_lambda_expression(y, body);
struct value* lambda_xy = new_lambda_value(NULL, x, lambda_y);
this->false_value = lambda_xy;
free_expression(lambda_y);
free_expression(body);
}
free_string(x);
free_string(y);
EXIT;
return this;
}