develooper Front page | perl.perl5.porters | Postings from November 2016

[perl #130038] Builtin variable for loop index in foreach

Thread Previous | Thread Next
From:
Ed Avis via RT
Date:
November 28, 2016 08:46
Subject:
[perl #130038] Builtin variable for loop index in foreach
Message ID:
rt-4.0.24-12192-1480322795-941.130038-15-0@perl.org
Translating the loop at compile time into a new builtin foreach_idx sounds sensible, and it effectively automates what the programmer currently has do to in the code.  But if $# is a lexical scoped at compile time to the for loop, it won't be available in subroutines called from the loop.  This makes it inconsistent with next/last/redo, which do work from subroutines (matching the enclosing loop at run time).  Personally speaking I'd be fine with that (I consider always allowing 'next' from a subroutine something of a wart on the language) but I just mention the asymmetry.

One advantage of a new builtin loopidx rather than $# would be that you could specify loopidx(LABEL).  This might be another point in favour of a compile-time translation approach, that it could allow loopidx(LABEL) to be implemented more easily.

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

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