On Thu, 2004-05-13 at 04:30, Rafael Garcia-Suarez wrote: > Aaron Sherman wrote: > > Is it a special type of calling convention, e.g.: > > > > sub s (Regex $pat, Str $replace, bool ?$i) is doublequotelike returns(Str) { > > Ooh, "doublequotelike" sounds so much 1984. > (Moreover it doesn't describe accurately the reality, which allows to > use different delimiters for the pattern and the replacement.)
Hmm... I think doublequotelike would work, as long as it were a superset of both sets of behaviors and the object that you get is neither a Regex nor a Str, but mutable into both (a sort of pre-parsed doublequotelike thing) and then in this case, you could optimize the conversion of both parameters, because you know what they'll be converted into. For example: role doublequotelike { has Parser::Perl6::ProtoString $.string; # Not sure how to say "conversion to Str calls this method" method as_string() returns(Str) {...} method as_regex() returns(Regex) {...} } doublequotelike.string would just contain a series of tokens (e.g. m/\s+$pattern/ yields (literal => '\s+', interpolate => '$pattern')). In this way, you can apply your Perl 5 or Perl 6 mode by simply deriving a new doublequotelike class. Is there some reason not to do that that I'm missing? Why use a macro here when that prevents you from ever using it as a method? More to the point, even if it is a macro, would this kind of facility be allowed for creating a method with the same syntax exposed to the user. Performing a regex on an object seems so common an idiom that I don't think it's healthy to make it such a special case. -- Aaron Sherman <[EMAIL PROTECTED]> Senior Systems Engineer and Toolsmith "It's the sound of a satellite saying, 'get me down!'" -Shriekback