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

subscripts are.... objects?

Thread Next
Yuval Kogman
April 12, 2005 08:58
subscripts are.... objects?
Message ID:

We blitzed a discussion on #perl 3 minutes ago, reaching the
conclusion that negated subscripts are cool.

So i was thinking:

subscripts are objects.

They are sets, really.

You can perform set operations on them:


is the subscript for everything but the second to last element.

By using a context enforcer (subscript [] ?, maybe since lists are
lazyy they can just be subscripts when used that way?) you can get a
subscript object, which you can then use in a subscript, and it
flattens out.

The set math is done by special casing junctions, perhaps?

my @array;


@array[$subscript | $other]; # union
@array[$subscript & $other]; # intersection

@array[!-1]; # -1 but false? this means that it's masking

my $not_1 = [!-1];

@array[$subscript & $not_1]; # subscript without -1
@array[$subscript | $not_1]; # subscript with -1, since it's a union
# with the complement of just -1

I've found myself replicating sets like these for accessing data
many a time in perl 5.

Maybe if refined this can be useful?

 ()  Yuval Kogman <> 0xEBD27418  perl hacker &
 /\  kung foo master: /me wields bonsai kittens: neeyah!!!!!!!!!!!!!!!!

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About