4 ms·
Sure, I'm reviewing the gambit code a bit. I'm really busy so I'll have to follow up later. Right off the bat I can tell you that Fexl's combinators aim to be
by fexl 17y ago
Sure, I'm reviewing the gambit code a bit. I'm really busy so I'll have to follow up later.
Right off the bat I can tell you that Fexl's combinators aim to be written in readable C.
I suppose the simplest combinator to show would be "I" (the identity function). In Fexl I have a file named "type_I.c" which says:
#include "node.h"
#include "type_I.h"
static struct node *reduce(struct node *parent)
{
return parent->RIGHT;
}
static struct type type = { reduce, clear_pair };
struct node *make_I(void)
{
return make_pair(&type,0,0);
}
(Quick note: all node values are reference counted. Cycles are impossible, and unnecessary because of the wonderful Y combinator.)
Speaking of Y combinator, here is "type_Y.c":
#include "node.h"
#include "type_app.h"
#include "type_Y.h"
static struct node *reduce(struct node *parent)
{
return make_app(parent->RIGHT,parent);
}
static struct type type = { reduce, clear_pair };
struct node *make_Y(void)
{
return make_pair(&type,0,0);
}
Those are easy. The most gnarly one is the S (fusion) combinator ... which ... oh well I might as well paste it in:
#include "node.h"
#include "type_app.h"
#include "type_S.h"
static struct node *reduce(struct node *parent)
{
if (0 == parent->LEFT->LEFT || 0 == parent->LEFT->LEFT->LEFT)
{
parent->type = parent->LEFT->type;
return parent;
}
struct node *x = parent->LEFT->LEFT->RIGHT;
struct node *y = parent->LEFT->RIGHT;
struct node *z = parent->RIGHT;
struct node *fun = make_app(x,z);
struct node *arg = make_app(y,z);
hold(fun);
hold(arg);
parent->type->clear(parent);
parent->LEFT = fun;
parent->RIGHT = arg;
return fun->type->reduce(parent);
}
static struct type type = { reduce, clear_pair };
struct node *make_S(void)
{
return make_pair(&type,0,0);
}
OK now I'm pushing the limits of long-windedness, but I just wanted to feed you some information right away while I work on some other things.