RE: RFC 152 (v1) Replace $self in @_ with self() builtin (not $ME )

[email protected] ("Myers, Dirk")
Newsgroups perl.perl6.language.objects
Message-ID <78445BA01DCED21197B400A0C9EA5F7E01E03096@exeug3>
Damian Conway:

> My forthcoming proposal will be that invocants still be passed as $_[0]
> by default, but that there be a pragma allowing $_[0] to be automagically
> shifted somewhere else during dispatch. For example:
>
>
>	sub method { print "I was called through: $_[0]";
>		     print "My args were: @_[1..$#_]";	}	#default

>	use invocant '$ME';
>	sub method { print "I was called through: $ME";
>		     print "My args were: @_";		}

Why couldn't(/shouldn't/wouldn't) this be more useful as a facility that
allows you to define a chunk of code that gets inserted in each sub routine?

I'm not sure what the general facility would look like, but it seems to me
like the "use invocant '<variable>'" pragma is just essentially sticking a:

	my <variable> = shift ;

as the first line in each method... wouldn't it be more fun to let people do
something like:

	use invocation 'my $ME = shift; print "I was called through : $ME" ;
print "My args were : @_" ;'

... which, of course, means that duplicating the method above is as simple
as:

	sub method {  # use invocation stuff gets shoved in here
	}

(Or, was it already intended that the implementation of 'use invocant' might
be some sort of compile-time macro?)

Dirk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.