[Nickle] Re: [AI] Nickle Growing Pains
Carl Worth
cworth at cworth.org
Thu Jan 6 10:55:28 PST 2005
On Wed, 01 Dec 2004 00:28:16 -0800, Barton C Massey wrote:
> 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 }
The enum-as-disjoint-union is an interesting implementation detail,
but I would hope I could use enum types without having to know about
it.
> 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;
> }
The code above was written to demonstrate void and <>. Rewriting in a
more conventional enum style gives:
typedef enum { a, b } e;
e v;
v = e.a;
enum switch(v) {
case a: printf("a\n"); break;
case b: printf("b\n"); break;
}
The "v = e.a" and "enum switch" syntax help hide the underlying
disjoint union quite well. But it leaks out quite badly with:
> v
a = <>
Can that be easily fixed to print "e.a" as expected?
-Carl
More information about the Nickle
mailing list