[Nickle] Re: [AI] Nickle Growing Pains
Barton C Massey
bart at cs.pdx.edu
Wed Dec 1 00:28:16 PST 2004
I'm trying to get a paper out, so you get the short version
:-). Here's a quick example:
typedef tree;
typedef union {
int leaf;
struct {
tree left, right;
} node;
} tree;
tree t = {
node = { left = { leaf = 5 }, right = { leaf = 3 } }
};
t
tree u = t;
t.node.left = u;
t
Run it and you should see
node = {left = leaf = 5, right = leaf = 3}
node = {left = node = {left = leaf = 5, right = leaf = 3}, right = leaf = 3}
Not sure where you decided <> was interesting :-). The deal is
that <> is the "unit" value: the sole value of type "void"
:-). For example, when you write
void f() {
}
you are actually writing shorthand for
void f() {
return <>;
}
since all Nickle functions return a value. It can
be useful to use the void type with Nickle's disjoint
union types.
enum { a, b }
is shorthand for
union { void a, void b }
which should probably make your head hurt :-(.
You can thus say things like
typedef enum { a, b } e;
e v;
v.a = <>;
union switch(v) {
case a: printf("a\n"); break;
case b: printf("b\n"); break;
}
which should print
a
Have fun with Nickle!
Bart
More information about the Nickle
mailing list