On Fri, Apr 23, 2004 at 02:20:20PM -0700, Jonathan Lang wrote: : "Then we simply claim that, under multiple dispatch, the "long name" of : any multi routine includes its signature, and that visibility is based on : the long name." (paragraph 3, "Multiple Dispatch") : : Is a routine's "returns" trait also included in a multi routine's "long : name"? That is, if I define : : multi method foo () returns scalar {...}; : multi method foo () returns list {...}; : multi method foo () returns hash {...}; : : would these be treated as three seperate routines, or as conflicting : declarations of the same one?
It's not included in the primary invocants, but it might well be considered as a tiebreaker just as a secondary invocant would be. Mostly though it's just cleaner to have one routine return an object that knows what to do in a given context than to try to guess via "want" semantics. Then you don't have to worry about guessing wrong under the indirection of my $value = foo(); ... say $value.{'key'}; say $value.[2]; say $value; And in fact, since the object can respond in all of those contexts, you don't ever have to guess. And if one or another of those values is difficult to calculate, you can always do it lazily. Larry