Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Context and coercion

10 views
Skip to first unread message

Joshua Choi

unread,
Apr 3, 2006, 10:23:28 PM4/3/06
to perl6-l...@perl.org
Kudos to all on the Perl 6 mailing list,

What's the conceptual difference (or relationship) between context and type
coercion? Is
$moose.prefix:<~>
the same as
$moose.coerce:<as>(Str)
for instance?

And forgive my brain, but how would you nicely define coercion in a class?
Like, could you spare an example?

Also, what's the point of making a whole grammatical category for "coerce"
that behaves like an infix operator?

Thanks in advance.

Larry Wall

unread,
Apr 3, 2006, 11:24:51 PM4/3/06
to perl6-l...@perl.org
On Mon, Apr 03, 2006 at 07:23:28PM -0700, Joshua Choi wrote:
: Kudos to all on the Perl 6 mailing list,

:
: What's the conceptual difference (or relationship) between context and type
: coercion? Is
: $moose.prefix:<~>
: the same as
: $moose.coerce:<as>(Str)
: for instance?

No difference.

: And forgive my brain, but how would you nicely define coercion in a class?


: Like, could you spare an example?

Currently something like:

multi submethod infix:<as> ($self: Str) {...}
multi submethod infix:<as> ($self: Int) {...}

or

multi sub infix:<as> (MyClass $self, Str) {...}
multi sub infix:<as> (MyClass $self, Int) {...}

: Also, what's the point of making a whole grammatical category for "coerce"


: that behaves like an infix operator?

In the current synopses there is no "coerce" grammatical category
any more. Everything is subsumed under infix:<as>, at least this week...
There's some discussion about whether it should simply be:

method as (Str) {...}
method as (Int) {...}

maybe with an "is deep" thrown in for good measure, but we haven't
quite got there yet.

Larry

Larry Wall

unread,
Apr 3, 2006, 11:43:08 PM4/3/06
to perl6-l...@perl.org
On Mon, Apr 03, 2006 at 08:24:51PM -0700, Larry Wall wrote:
: There's some discussion about whether it should simply be:

:
: method as (Str) {...}
: method as (Int) {...}
:
: maybe with an "is deep" thrown in for good measure, but we haven't
: quite got there yet.

Er, to have multiple of them in the same class, that would of course
have to be:

multi method as (Str) {...}
multi method as (Int) {...}

Generally, I love to travel. Specifically, I love the fact that
jet lag is a such a convenient excuse for stupidity.

Larry

0 new messages