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:
John Porter
Date:
February 2, 2001 09:01
Subject:
Re: assign to magic name-of-function variable instead of "return"
Message ID:
20010202120129.A3493@min.net
David L. Nicol wrote:
> 
> I recalled hearing about a language where
> you set the return value of a function by 
> assigning to the name of the function within the function body,

Fortran and Pascal do that.  Maybe others.


> It would mean that
> 
> 	sub subname(proto){
> 		# in here, the bareword "subname" is a magic
> 		# alias for the lvalue this routine is getting 
> 		# assigned to, if any.
> 	}

But that raises a potential conflict with another proposed magical
meaning of the subname within the sub: as a label for the beginning
of the sub.  I.e.

	sub foo {
		bar();
	}

is effectively

	sub foo {
	foo:
		bar();
	}

so that, for example, redo works kinda like the perl5 goto &foo:

	sub foo {
		bar();
		redo; # which is shorthand for:
		redo foo; # like goto &foo;
	}

Proposals along these lines came up in the thread "$a in @b",
in the subsequent discussion of RFC 199, and probably in other
threads.


-- 
John Porter

A pessimist says the CPU is 50% utilized.
An optimist says the CPU is 50% unutilized.
A realist says the network is the bottleneck.


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