develooper Front page | perl.perl6.language.objects | Postings from August 2000

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

From:
Myers, Dirk
Date:
August 28, 2000 09:15
Subject:
RE: RFC 152 (v1) Replace $self in @_ with self() builtin (not $ME)
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
	




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About