develooper Front page | perl.perl5.porters | Postings from August 2013

[perl #118089] Feature: list slices to the end

Thread Next
From:
Father Chrysostomos via RT
Date:
August 19, 2013 14:30
Subject:
[perl #118089] Feature: list slices to the end
Message ID:
rt-3.6.HEAD-1081-1376922609-36.118089-15-0@perl.org
On Wed Jul 10 23:17:35 2013, aaron@priven.com wrote:
> On Wed, Jul 10, 2013 at 7:03 PM, Aaron Priven <aaron@priven.com>
>    wrote:
> How would new slicing syntax work with object methods and other times
>    you'd want to pass a slice specification to a sub?
> 
> 
> On Jul 10, 2013, at 5:41 PM, David Nicol wrote:
> > It wouldn't. That's another fine argument against introducing
>    situational syntaces,
> >
> > If ranges were to defer their expansion as long as possible, a range
>    such as 5 .. -2 could exist as a range object and get passed as
>    part of a slice specification, where it would mean something (from
>    the sixth element to the second element from the end) instead of
>    getting immediately evaulated to the empty list. How to wrap that
>    up for passing as one argument however? Maybe within square
>    brackets, as contents of an array-ref, expansion deferred as long
>    as possible, so if you defer the flattening until actually
>    constructing the slice, you have succeeded.
> 
> Yes, this is what I meant by suggesting a new slice syntax with a
>    quote-like operator. So:
> 
> @ary[qs/slice syntax goes here/]
> 
> or
> 
> $obj->slice(qs/slice syntax goes here/)
> 
> And it would become a slice object of some sort or other, that would
>    not be processed until the slice actually occurred.
> 
> Like regex syntax, it could have basically nothing to do with regular
>    perl syntax. (I had this whole idea of using Set::IntSpan objects
>    before realizing that negative numbers mean something completely
>    different to Set::IntSpan. Still, there's something about using
>    hyphens instead of dots for ranges that appeals to me)
> 
> Of course, [qs/3-/] probably wouldn't satisfy people looking to make
>    [3..] work. I'm not sure how to introduce it more succinctly given
>    the paucity of ASCII characters. @a:[3-5] ? With Unicode we could
>    have @a⁅3-5⁆ or something.
> 
> Or perhaps none of this makes any sense at all.

I started to implement [1..] and found myself liking your idea more and
more.

A CPAN module could provide a function that allows slice(@array,
qs(...)) or slice(@array, "1.., 3..5") as well as slice(a_list(), ...).
 There is plenty of room for experimentation here, and it doesn’t have
to be in core.

Anyway, my unfinished work is on the sprout/slice branch.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=118089

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