CARVIEW |
Select Language
HTTP/2 200
cache-control: max-age=43200
server: Combust/Plack (Perl)
vary: Accept-Encoding
content-encoding: gzip
content-length: 2592
content-type: text/html; charset=utf-8
last-modified: Mon, 13 Oct 2025 03:15:10 GMT
traceparent: 99d6a1424f87c785bfc4b4329efb8d62
strict-transport-security: max-age=15768000
Re: Proposal: Make @a and @@a different variables - nntp.perl.org
Front page | perl.perl6.language |
Postings from December 2008
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About

Re: Proposal: Make @a and @@a different variables
Thread Previous | Thread NextFrom:
Daniel RuosoDate:
December 16, 2008 10:38Subject:
Re: Proposal: Make @a and @@a different variablesMessage ID:
1229452819.19488.79.camel@cajueiroEm Ter, 2008-12-16 às 18:47 +0100, TSa escreveu: > > # the following will require a flatenning to get the actual index > > say @a[3]; > Could we not shift the problem into a more complicated form > of the size of the array? Here it has size 0+3+0 but each of the > summands could be lazy and hence infinite or at least finite with > unknown value. The number of "summands" might be also unknown. i.e.: map. when you have my @a <== map { ... } <== something() you can't really know how many elements you have in the first dimension... > In any case the flat view @a has to step at most the first iterator in > the array I'm not sure I see what you mean, but I presume you mean "the first iteration". In that case, if that iteration returns an empty capture, it will continue iterating until it returns at least one item. But that iteration can then return several items which need to be stored in the lazy list. > whereas @@a can look beyond that when indexed with a slice, that is > something with semicolon in it. Or the iterations of "map" and "grep"... > An out of bounds access like @a[3] can be answered without flattening, > right? I consider counting the number of items in the inner dimension to be (a simplified) flattening, think of: my @@a <== map { $^a == 2 ?? map { $^b == 2 ?? map { $^c == 2 && $b == 2 && $a == 2 ?? (1,2,3) !! () }, 1, 2, 3 !! () }, 1, 2, 3 !! () }, 1, 2, 3; That would result in (();(();(1,2,3);());()) Which is considerably more complex than the first example and have the following example slice accesses: @@a[1]; # returns (();(1,2,3);()) @@a[1;1]; # returns (1,2,3) @@a[1;1;0] # returns 1 Trying to access @a[0] would result in a recursive flattening until it gets to the element that would otherwise be accessed by the slice @@a[1;1;0] So it's not just a matter of counting 0-3-0, because to get the first 0, you need to recursively flatten the inner dimmension until you realize it's really empty. If we allow that to be flattened at the beginning, it will simply consume the iterator until it gets an element. > In general I'm in favor of making @a and @@a distinct because > otherwise the first @ in @@a feels like an operator instead like > a twigil that belongs to the variable like $ belongs to $a which > is also distinct from @a. That's an important point. I think it would be consistent that '@@a' should be the variable name, just as '@a', '$a' or any other. Specially since '@@' is not a sigil and a twigil, but a sigil of two characters. > Since one could also go with a shaped @a I think the choice of @@a > versus @a is a bit like the choice between a @a and an anonymous array > in a $ var ala $a = [] which can be handled through $a almost like @a. I'm not sure I understood that, but I think you're saying that slice context could be seen just as a regular context, as scalar and list context, which is something that I agree. > > @a =!= @@a :test; > BTW, what does the :test mean there? This is the proposed syntax for integration of test-driven-development in the language built-ins. danielThread Previous | Thread Next
- Proposal: Make @a and @@a different variables by Daniel Ruoso
- Re: Proposal: Make @a and @@a different variables by Larry Wall
- Re: Proposal: Make @a and @@a different variables by TSa
- Re: Proposal: Make @a and @@a different variables by Moritz Lenz
- Re: Proposal: Make @a and @@a different variables by Daniel Ruoso
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About