Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

sexp

Name: Anonymous 2015-03-13 3:34

Is this a sane representation for s-expressions?

struct O
{
union {
Cell *o;
char *a;
};
int type;
};

struct Cell
{
O car, cdr;
};

Name: Anonymous 2015-03-13 4:32

>>1
No.

type 'a sexp = Atom of 'a | Sexp of 'a sexp

Hint: change the char to a void pointer and the discriminant to an enum. It's still not type safe but you're using C and this is the best you can do.

This way you can construct a s-exp with an ADT of the atoms you want or an object for a more traditional opaque unityped language approach.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List