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

Re: Sane (less insane) pair semantics

Thread Previous | Thread Next
From:
Luke Palmer
Date:
October 9, 2005 14:42
Subject:
Re: Sane (less insane) pair semantics
Message ID:
7ca3f0160510091442k5b22eb89j41e143d44f8d52a5@mail.gmail.com
On 10/9/05, Uri Guttman <uri@stemsystems.com> wrote:
> >>>>> "IB" == Ingo Blechschmidt <iblech@web.de> writes:
>   IB>       sub foo ($a) {...}
>
> works for me. but what about lists and arrays?
>
>         my @z = ( 'a', 1 ) ;
>         foo( @z )       # $a = [ 'a', 1 ] ??

Yep.

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

    $a = [ a => 1 ]

You passed an array.  The parameter gets an array.

> 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

Yeah, I think your expectations are correct.

Basically, * takes whatever kind of object it is (array, hash, pair)
and pretends that you wrote its contents literally into the argument
list.

Luke

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