Default invocant of methods

6 views
Skip to first unread message

Ingo Blechschmidt

unread,
May 27, 2005, 4:59:25 PM5/27/05
to perl6-l...@perl.org
Hi,

what is the default invocant of methods?

method blarb ($normal_param) {...}
# Same as
method blarb (Class | ::?CLASS $invocant: $normal_param) {...}
# or
method blarb (::?CLASS $invocant: $normal_param) {...}
# ?

I prefer the latter, as then one can't accidentally call a instance
method on the class -- i.e.
Foo.blarb # will die.

You can always specify Class as invocant, if you want to have a class
method.

Opinions?


--Ingo

--
Linux, the choice of a GNU | Elliptic paraboloids for sale.
generation on a dual AMD |
Athlon! |

Yuval Kogman

unread,
May 28, 2005, 7:24:19 PM5/28/05
to Ingo Blechschmidt, perl6-l...@perl.org
On Fri, May 27, 2005 at 22:59:25 +0200, Ingo Blechschmidt wrote:
> Hi,
>
> what is the default invocant of methods?
>
> method blarb ($normal_param) {...}
> # Same as
> method blarb (Class | ::?CLASS $invocant: $normal_param) {...}
> # or
> method blarb (::?CLASS $invocant: $normal_param) {...}
> # ?
>
> I prefer the latter, as then one can't accidentally call a instance
> method on the class -- i.e.

I think I do too... In p5 this was a bit too easy to abuse.

However, I think this introduces another issue- how can we subvert
the parameter checking?

Sometimes it makes sense too call a method on a class instead of a
module, even if the author didn't think of it first. I'd like that
to be possible, and further more, I'd like subsequent calls from
that method to also ignore the type checking.

I think the mechanism I want is like C casts, in the sense that they
don't really do anything, they are more like "oh, it's ok, it can
pass as a ...".

--
() Yuval Kogman <nothi...@woobling.org> 0xEBD27418 perl hacker &
/\ kung foo master: /me sneaks up from another MIME part: neeyah!!!!!

Larry Wall

unread,
May 31, 2005, 7:53:49 PM5/31/05
to perl6-l...@perl.org
On Fri, May 27, 2005 at 10:59:25PM +0200, Ingo Blechschmidt wrote:
: Hi,

:
: what is the default invocant of methods?
:
: method blarb ($normal_param) {...}
: # Same as
: method blarb (Class | ::?CLASS $invocant: $normal_param) {...}
: # or
: method blarb (::?CLASS $invocant: $normal_param) {...}
: # ?
:
: I prefer the latter, as then one can't accidentally call a instance
: method on the class -- i.e.
: Foo.blarb # will die.

It will almost certainly die anyway the moment you try to do something
instancely with it.

: You can always specify Class as invocant, if you want to have a class
: method.

Hmm, well, maybe, provided Class is the parent of all possible class
classes, but it's not entirely clear we want to assume that. We could
get potentially get other kinds of metaclass and dispatcher classes
involved, especially if we've inherited things across languages.
At some point you have to trust your dispatcher to hand you things
you can work with, and that may involve some kinds of structural
or role equivalence rather than just class name equivalence.

Hmm, maybe Class is really a role then, and anything that "does Class"
can pretend to be one.

: Opinions?

From the efficieny viewpoint, I'd rather leave it untyped, and rely
on the dispatcher to do my type checking. Of course, there are times
you'd like the compiler to know that the type of $?SELF is consistent
with the current class, but that's a different matter than run-time
type checking, which an explicit type tends to imply.

Larry

Reply all
Reply to author
Forward
0 new messages