I wanted to give implementations in different programming languages for constructing the lambda calculus of Boolean elements and the NOT operator.
It:
TRUE = lx.ly. x
FALSE = lx.ly. y
NOT = lx. x FALSE TRUE
This is trivial to do in Javascript and Python, for example,
var TRUE = function(x,y){ return x;}
var FALSE = function(x,y){ return y;}
var NOT = function(b){ return b(FALSE,TRUE) ; }
but I can't figure out how to do this in C.
A naive idea to implement something like this
lambda true(lambda x, lambda y){ return x ; }
lambda false(lambda x, lambda y){ return x ; }
lambda not(lambda (b)(lambda, lambda) ){ return b(false,true) ;}
not possible in C because it typedefdoes not allow a recursive definition
typedef void (*lambda)(lambda,lambda) ;not valid in C
Is there any way to do this in C? and is there a way to do this that makes sense to use as a case study? That is, if the syntax starts to become cumbersome, it ends up defeating its purpose ...
Finally, if C is ultimately too limited, the answer in C ++ will also work for me, albeit with the same “complexity” of limitation
C.
EDIT:
,
typedef void *(*bol)() ;
bol true(bol x, bol y){ return x ; }
bol false(bol x, bol y){ return x ; }
bol not(bol b ){ return b(false,true) ;}
int main(){
bol p = not((bol)true);
return 0;
}
EDIT2: , , , .
, @Antti Haapala @n.m , C.
, ++ .