develooper Front page | perl.perl5.porters | Postings from January 2014

Re: Range idea

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
January 23, 2014 16:33
Subject:
Re: Range idea
Message ID:
20140123163253.GA10247@fernweh.localdomain
* H.Merijn Brand <h.m.brand@xs4all.nl> [2014-01-23 13:30]:
> Why cannot we use open range operators in this case?
>
> Both [n ..] and [n ...] are currently syntax errors

* Xiao Yafeng <xyf.xiao@gmail.com> [2014-01-23 14:20]:
> how about @foo[3..*] ?

* Dr.Ruud <rvtol+usenet@isolution.nl> [2014-01-23 15:10]:
> Maybe get a contextual $# for that:
>
> perl -wE'
>   $# = 3;
>   say for qw( a b c d )[2 .. $#];
> '
> $# is no longer supported at -e line 2.
> $# is no longer supported at -e line 3.
> c
> d

* Dr.Ruud <rvtol+usenet@isolution.nl> [2014-01-23 15:15]:
> perl -wE'
>   say for qw( a b c d )[2 .. NaN];
> '
>
> perl -wE'
>   say for qw( a b c d )[2 .. Inf];
> '
> Range iterator outside integer range at -e line 2.

(Re: the last proposal: those already have meanings, even if those
meanings are not too commonly useful.)

I have to wonder why everyone is obsessed with inventing magic syntax?

Why not simply add a weak keyword and avoid the entire syntax design
exercise?

   qw( a b c d )[2 .. lastindex]

Longer than using line noise or an absence as syntax, but then again it
automatically follows the orthogonality/generalisation principle that
Zefram explained.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

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