On Tue, 12 Jun 2001, Stephen White wrote: > > Maybe it's best to use "new" when there is a guarantee of returning a new > > object at every call (like Tuple); > > and to use "of" when all returned objects are cached permanently (List > > and Union). > Isn't the caching an implementation detail? > A singleton pattern uses "new", even when subsequent calls will return > the cached object created with the first call. Well, the caching is, sorry. What's more important is that two equally constituted Union or List types are equal, whereas two equally constituted Tuple types are not: "And" and "Or" are both tuple([:left,Expr],[:right,Expr]), but their semantics differ. > > Btw I forgot to mention that in RX11 I use "Either" instead of "Union". > > Do you prefer the name "Either" ? > I think I know what you're aiming for. Union is a list of possible parse > paths, and only one of them will be taken? > Perhaps "Grammer", "Rules" or "Context"? They are not "parse paths", because RubyAST is written without regards to parsers and parsing. It's simply a type constraint: a certain parameter or attribute will be of type Foo OR of type Bar. > Seeing the example you posted: > > QRegexp = tuple([:pattern,QString|IString],[:flags,String]) > > makes it clearer how you intend this to be used. My suggestions would > make the above into: > QRegexp = Tuple[:pattern, Union[QString, IString], [:flags, Union[String]] > Which doesn't look as good. You have to put brackets around :pattern,Union[QString,IString], because it's a parameter descriptor. However you did it right for the :flags descriptor, but you missed one closing-bracket. Now, constraint-wise, Union[String] is fully equivalent to just String, so why use an Union in this case? matju