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

Re: Strange interaction between pairs and named binding

Thread Previous | Thread Next
From:
Larry Wall
Date:
July 22, 2005 15:40
Subject:
Re: Strange interaction between pairs and named binding
Message ID:
20050722224034.GA19392@wall.org
On Tue, Jul 19, 2005 at 12:25:02PM +0800, Autrijus Tang wrote:
: On Mon, Jul 18, 2005 at 03:48:55PM -0700, Brent 'Dax' Royal-Gordon wrote:
: > Autrijus Tang <autrijus@autrijus.org> wrote:
: > > This currently works in Pugs:
: > >
: > >     for [1..10].pairs -> Pair $x { say $x.value }
: > >
: > > But this does not:
: > >
: > >     for [1..10].pairs -> $x { say $x.value }
: > >
: > > Because the ruling that pairs must not be bound to parameters that are
: > > not explicitly declared to handle them.  Is this a desirable behaviour?
: > 
: > How much violence would be done to the language if we declared that
: > block (i.e. closure with no "sub" keyword) parameters defaulted to
: > Item|Pair, while sub parameters defaulted to plain Item?  I can't
: > imagine named arguments are going to be used very often on blocks,
: > which tend to be things like loop bodies...
: 
: If the Bare code object (including pointy and non-pointy) default their
: parameter types to "Any" (that is, Item|Pair|Junction), then all of
: these would work:
: 
:     for [1..10].pairs { say(.value) }
:     for [1..10].pairs { say($^x.value) }
:     for [1..10].pairs -> $x { say($x.value) }
:     for 1|2, 3|4 { say(.values) }
:     for 1|2, 3|4 { say($^x.values) }
:     for 1|2, 3|4 -> $x { say($x.values) }

I dunno.  I'm inclined to say that it should default to Item|Pair, and
let people say Any explicitly if they really want to suppress autothreading.
Otherwise conditionals and switches are going to behave oddly in the
presence of "accidental" junctions.

Alternately we could try to distinguish explicit pairs from generated
pairs, and require explicit pairs (or * marked generated pairs) to
transition to the named zone.

Larry

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