develooper Front page | perl.perl6.language | Postings from October 2005

Re: Sane (less insane) pair semantics

Thread Previous | Thread Next
From:
Uri Guttman
Date:
October 9, 2005 12:09
Subject:
Re: Sane (less insane) pair semantics
Message ID:
x74q7qqzhz.fsf@mail.sysarch.com
>>>>> "IB" == Ingo Blechschmidt <iblech@web.de> writes:


  IB> * "(key => $value)" (with the parens) is always a positionally passed
  IB>   Pair object. "key => $value" (without the parens) is a named
  IB>   parameter:

  IB>       sub foo ($a) {...}

  IB> * Unary "*" makes a normal pair variable participate in named binding:

  IB>       foo(*$pair);  # named parameter "a", $a will be 42

  IB> * Same for hashes:

  IB>       my %hash = (a => 1, b => 2, c => 3);

  IB>       foo(%hash);   # positional parameter, $a will be \%hash

  IB>       foo(*%hash);  # three named parameters

  IB> Opinions?

works for me. but what about lists and arrays?

	my @z = ( 'a', 1 ) ;
	foo( @z )  	# $a = [ 'a', 1 ] ??

	my @z = ( a => 1 ) ;
	foo( @z )	# $a = pair( a => 1 ) or does that need * too?

same questions for lists (this shows a nested sub call)

	sub bar { return ( a => 1 ) }
	foo( bar() )	# i would expect $a == ( a => 1 ) since there is
			# no *

	foo( *bar() )	# i would expect $a == 1

i think i covered most/all of the variations. but this needs to be
hammered down for all of them.

thanx,

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

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