Re: Extension proposal
| From: | Pedram Nimreezi | Date: | Sun, 28 Oct 2007 23:48:34 +0000 |
| Subject: | Re: Extension proposal | ||
| References: | 1 2 3 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-4911@lists.php.net to get a copy of this message | ||
+1
On 10/28/07, Paul Chandler <pestilence669@users.sourceforge.net> wrote:
> Antony,
>
> Do you need any other reason than "it's like Python?" :)
>
> First, there's the memory conservation. You don't need to pre-allocate an
> array. Second, it's an objectified range iterator / generator. This means
> you can combine it with SPL and even your own custom iterators.
>
> For example: here's some, arguably nasty, code:
> <php?
> // filters odd values, after squaring values 1 .. 20
> // the filters are not included, but are four-line
> // descendents of FilterIterator
> foreach (
> new OddOnlyFilter(new SquareFilter(xrange(1, 20))) as $i
> ) // do something
>
> // ...and... //
>
> $x = new AppendIterator;
> $x->append(xrange(1, 7));
> $x->append(xrange(929, 429, -100));
>
> foreach ($x as $i) // do something
> ?>
>
> My examples are bad, I apologize. The potential is difficult to convey
> without a complicated real-world example. The whole reason for the extension
> is for a 3x+ improvement over my reference implementation.
>
> It's not revolutionary or anything, but offers a little more flexibility and
> brings something to PHP that's already in other languages.
>
> On 10/26/07 12:19 AM, in article 472194F0.4070401@daylessday.org, "Antony
> Dovgal" <tony@daylessday.org> wrote:
>
> > On 26.10.2007 03:17, Paul Chandler wrote:
> >> Hello,
> >>
> >> I have a very simple extension on SourceForge that I'd like to release with
> >> PECL. In a nutshell, it's an iterator-based replacement for range(), like
> >> Python's. It's intended use is within foreach loops. I don't think
> >> it'll be
> >> a high-demand extension, but Python converts might appreciate it.
> >>
> >> <?php
> >> foreach (range(0, 1000000) as $i) // do something
> >>
> >> // vs. //
> >>
> >> foreach (xrange(0, 1000000) as $i) // do something
> >> ?>
> >
> > What's the advantage of it? (except that it's like Python).
> > Also I don't see any differences from range() in the example code given above.
>
> --
> PECL development discussion Mailing List (http://pecl.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
~
Pedram Nimreezi