Re: Pugs Bug

2 views
Skip to first unread message

Wolverian

unread,
Apr 5, 2005, 2:36:18 AM4/5/05
to perl6-l...@perl.org
(Replying to p6l instead of p6c as requested.)

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

signature.asc

Adriano Ferreira

unread,
Apr 5, 2005, 7:53:30 AM4/5/05
to perl6-l...@perl.org
> Shouldn't these be just methods?

I guess not. This is Perl and OO is not mandatory, or even desirable
all the time.

Adriano.

Larry Wall

unread,
Apr 5, 2005, 12:21:41 PM4/5/05
to perl6-l...@perl.org
On Tue, Apr 05, 2005 at 09:36:18AM +0300, wolverian wrote:
: (Replying to p6l instead of p6c as requested.)

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

Juerd

unread,
Apr 5, 2005, 12:40:21 PM4/5/05
to perl6-l...@perl.org
wolverian skribis 2005-04-05 19:31 (+0300):
> Does ~@array.words DWIM, by the way? I'm not sure about the precedence.

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

Wolverian

unread,
Apr 5, 2005, 12:31:40 PM4/5/05
to perl6-l...@perl.org
On Tue, Apr 05, 2005 at 09:21:41AM -0700, Larry Wall wrote:
> 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.

"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

signature.asc

Larry Wall

unread,
Apr 5, 2005, 1:44:18 PM4/5/05
to perl6-l...@perl.org
On Tue, Apr 05, 2005 at 07:31:40PM +0300, wolverian wrote:
: Does ~@array.words DWIM, by the way? I'm not sure about the precedence.

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

Reply all
Reply to author
Forward
0 new messages