CARVIEW |
Select Language
HTTP/2 200
cache-control: max-age=43200
server: Combust/Plack (Perl)
vary: Accept-Encoding
content-encoding: gzip
content-length: 1960
content-type: text/html; charset=utf-8
last-modified: Sun, 12 Oct 2025 13:48:43 GMT
traceparent: 2f831c3df61ae3429602ebd4c64f5671
strict-transport-security: max-age=15768000
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

Proposal: Make @a and @@a different variables
Thread NextFrom:
Daniel RuosoDate:
December 16, 2008 05:34Subject:
Proposal: Make @a and @@a different variablesMessage ID:
1229434591.19488.24.camel@cajueiroHi, One of the hardest features in Perl 6 is the slice context. It is undoubtfully usefull, since it provides semantics to acces each iteration of a map, for instance. But there's one thing in the spec that makes not only slices, but the lists themselves considerably harder to implement, and that is the idea that a slice is a view of a list. my @@a = map { $^a == 2 ?? 1,2,3 !! () }, 1, 2, 3; say @a[0]; # this should print 1. say @@a[0]; # this should print (). say @a[1]; # this should print 2. say @@a[1;0]; # this should print 1. That happens because '@a' and '@@a' are the same variable, just different views of that variable. That being said, we should note that this example looks simple because we have almost no lazyness implied (since there's an assignment in the first line), every list access requires the evaluation of the flatenning of the list. my @@a = ((),(1,2,3),()); # the following will require a flatenning to get the actual index say @a[3]; This looks much more complicated when you have a lazy list... my @a <== map { $^a == 2 ?? 1,2,3 !! () }, 1, 2, 3; # the line below will require two map iterations to get a value, # and at that time, there will be three values available say @a[0]; # having to support a slice view here will require the lazy list # to always be a lazy slice, and each access will require a flatenning # of the values already obtained to only then decide if it has to # obtain more items say @a[2]; This all makes me think that it would be much easier if the slice existed on its own, which would mean: # this will provide only a flatenned view my @a <== map { $^a == 2 ?? 1,2,3 !! () }, 1, 2, 3; # and this will provide a slice view my @@a <== map { $^a == 2 ?? 1,2,3 !! () }, 1, 2, 3; # but @a and @@a are different values @a =!= @@a :test; # and trying to get the slice on @a will fail say @a[0;1]; # fail # and you still can flatten the slice if you want to... # and it can preserve the lazyness my @b <== @@a; # or enforce a mostly eager level my @c = @@a; So, what do you think? danielThread 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