develooper Front page | perl.perl6.language | Postings from February 2001

Re: assign to magic name-of-function variable instead of "return"

Thread Previous | Thread Next
From:
David L. Nicol
Date:
February 5, 2001 12:51
Subject:
Re: assign to magic name-of-function variable instead of "return"
Message ID:
3A7F120F.8B78BA0D@kasey.umkc.edu
abigail@foad.org wrote:

> Does that mean there's going to be a @__ as well, for uses in list context?
> If so, what happens with:
> 
>     sub some_sub {
>         @__ = qw /foo bar baz/;
>     }
> 
>     my $fnord = some_sub;
> 
> If there isn't going to be a @__ of some sorts, how is the case of the sub
> being called in list context going to be handled?
> 
> Abigail

If $__ is a reference to our lvalue, if any, instead of an alias, since
references are all scalar, we can take C<ref($__)> to get a finely
grained C<want> function.

And when the sub is called in list context, @$__ will be the list.
This allows intrusive functionality to fiddle with lvalue parts:

	sub DirectBubbleSort(){
		my ($i,$t) = (-1,0);
		while (++$i <= $#$__){
			$$__[$i] > $$__[1+$i] and $t++ and @$__[$i,1+$i] = @$__[1+$i,$i];
		};
		$t and @$__ = DirectBubbleSort;	
	}

	@SomeList = DirectBubbleSort; # instead of DirectBubbleSort(\@SomeList)



-- 
                      David Nicol 816.235.1187 dnicol@cstp.umkc.edu
                      www.tmcm.com, dammit


Thread Previous | Thread Next


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