On Mon, Apr 04, 2005 at 10:39:16AM -0700, Larry Wall wrote:
> (Now that builtins are just functions out in * space, we can probably
> afford to throw a few more convenience functions out there for common
> operations like word splitting and whitespace trimming. (Specific
> proposals to p6l please.))
Shouldn't these be just methods?
> Larry
--
wolverian
I guess not. This is Perl and OO is not mandatory, or even desirable
all the time.
Adriano.
Depends on whether part of the "convenience" consists of coercing
the argument to a string in the first place. In all likelihood these
would be multimethods with a single definition, so that if you did
add other definitions of words() or trim(), it would use MMD to try
to figure out which way you probably wanted it coerced.
Plus you really don't want to clutter the Str type with every little
thing you might want to do with a string. "foo".open() will probably
work, but only because it doesn't find a Str.open and fails over to
MMD dispatch, which ends up finding a filehandle constructor.
But suppose words() were a singular multimethod. If you said
words(@array)
it would call &words<Str>, which would (I hope, since arrays know
about string context) coerce @array to a string with ' ' between the
elements, and then split that string into words. But some people might
prefer that to fail, and force people to use
words(~@array)
words("@array")
Maybe there's a pragma that lets you control how much coercion happens.
Larry
Yes, . is supertight.
Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html
"foo".open is just weird. Here I would definitely want at least a
warning, if just for my sanity.
> words(@array)
On the other hand, @array.words seems just as natural as $string.words
to me. I'm not sure how to reconcile this.
Does ~@array.words DWIM, by the way? I'm not sure about the precedence.
> Maybe there's a pragma that lets you control how much coercion
> happens.
use coercion :oppressively; # They're adverbs, after all!
> Larry
--
wolverian
That depends on whether you mean
(~@array).words
or
~(@array.words)
It happens to mean the latter. A . binds tighter than a symbolic
unary. In fact, it binds tigher than anything that is not a term,
so that, to the first approximation, a string of things separated by .
can always be thought of as a sort of term with respect to any other
operators. Standard Perl 6 will never define any precedence levels
between . and term.
Larry