[Nickle]Union values

Carl Worth nickle@nickle.org
Fri, 26 Jul 2002 21:21:27 +0000


Keith,

I really like this! A few comments.

On Jul 26, Keith Packard wrote:
 > 	<expr> = <type>.<member> ( <value> )	for non-void members
 > 	<expr> = ( <type>.<member> ) <value>	for non-void members
 > 
 > It's seems obvious to me that the ( <type>.<member> ) <value> form is
 > useless and should be discarded.

That's not as obvious to me. Maybe I'm just slow to grasp new syntax,
but I can't help but reading this as a function call every time I look
at:

 > 	x = u.i (10)

On the other hand, the following syntax seems to parallel the
assignment of structured values quite well. (This, in spite of the
fact that I've been lobbying to get rid of the type in that case):

 > 	x = (u.i) 10

But I agree that these are redundant and we don't need/want both.

 > I've extended the case syntax to include a name which is bound to the
 > referenced union member and whose type is the type of the named
 > member of <expr>. 
 >
 > 	case <member> <name>:
 > 		statements (involving <name>) ...

This is nice. And I'm not having any trouble reading this new syntax. :)

 > Because <name> is implicitly typed, I've made it illegal to fall through 
 > into one of these cases:

It seems potentially confusing to have a "switch" that falls through
and a "union switch" that does not.

It would be another departure from C, but one option would be to make
the "switch" not fall through either. In that case, new syntax for an
explicit fall-through could also be provided. (Some might argue that
this would be fixing something that is broken in C anyway).

The hardest thing about that is that it could break a lot of existing
code without any warning.

 > I think this change makes unions less onerous to deal with.  If we agree, 
 > I'd like to also propose that the NULL pointer values be eliminated from 
 > nickle entirely.  They are an endless source of typechecking grief and 
 > are better implemented using unions with void members:

Yes, unions are looking very appealing now. I don't see any problem
eliminating NULL pointers in favor of unions with void
members. Functions that return straight pointers will be so much more
reliable this way.

Thanks for the example list implementation.

-Carl

-- 
Carl Worth                                        
USC Information Sciences Institute                 cworth@east.isi.edu
3811 N. Fairfax Dr. #200, Arlington VA 22203		  703-812-3725