Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62147 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23845 invoked from network); 14 Aug 2012 16:42:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Aug 2012 16:42:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=aaron@aaronholmes.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=aaron@aaronholmes.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain aaronholmes.net from 209.85.213.170 cause and error) X-PHP-List-Original-Sender: aaron@aaronholmes.net X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:59551] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 00/9D-00812-0008A205 for ; Tue, 14 Aug 2012 12:42:41 -0400 Received: by yenm10 with SMTP id m10so735492yen.29 for ; Tue, 14 Aug 2012 09:42:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=wITF6z1lUdtWelBA0EiAC7oJOzPmGuMc93fnFTDMmgc=; b=pveNXYYb01+oAWIXAqhizyIrrzbpP/Vj/kKyFWD0i/eWfoPkYbD9LjomagBRx7lgge 0LwHMB6gTK1o8UI/CDCAq2O9OP5g2QEGzt8ySzwzayDgqQUdyg/wqyqfLTaa47KT26jM bKHOvVXQf1v602JvGAjih0TawdOQh3tzJ7/QnmdjmNgjma7baXbMnkz9VJ0JtOsT1GL2 g6bowoxTJOEmJV7kTxbaUMmcSPoAR7MiCa7sDh2852z03V+CTL9+LrrmhPRVOwZEaZmI GN3sELKdZCzbP2NnwhIpgE2syBzt6j7BUXddt07pkJU+Az1Lj0oZJVbTyMRYB7ZfvQee UQjw== Received: by 10.50.36.195 with SMTP id s3mr12881306igj.63.1344962557925; Tue, 14 Aug 2012 09:42:37 -0700 (PDT) Received: from aaronh-macbook.local ([38.122.108.2]) by mx.google.com with ESMTPS id aj1sm12010235igc.1.2012.08.14.09.42.36 (version=SSLv3 cipher=OTHER); Tue, 14 Aug 2012 09:42:37 -0700 (PDT) Message-ID: <502A7FFB.1090502@aaronholmes.net> Date: Tue, 14 Aug 2012 09:42:35 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: internals@lists.php.net References: <50280D37.10109@moonspot.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmRmo5/wXAiy0CypYlybipUYBZzARb6SCc6fAC/d16UZDMb/8GDtakzXuzTjq3YqbaphunO Subject: Re: [PHP-DEV] [RFC] Generators From: aaron@aaronholmes.net (Aaron Holmes) On 8/13/12 9:09 AM, Nikita Popov wrote: > On Sun, Aug 12, 2012 at 10:08 PM, Brian Moon wrote: >> Also, not allowing rewinding is unintuitive for something that is an >> iterator in PHP. If I can foreach() it and I can call next() on it, I expect >> to be able to reset() it as well. IMO, you would need to issue a FATAL PHP >> error if that simply is not allowed. Or you have to have a second syntax for >> what to do in that case. At that point, you are implementing Iterator. > Currently I'm planning to implement the following behavior for rewind(): > > * If before first yield: Resume to first yield (this priming behavior > is common to all the Iterator methods) > * At first yield: No-op > * After first yield: Recoverable fatal error > > So this would allow you to call ->rewind() after creating the > generator, but will throw an error if you try to do so later. > My perspective is that generators are intended to generate and yield a result, not so much to iterate over a known set of results. Thus, the results not really being known, there is nothing to rewind to. Rewinding would also presumably require more state control, or keeping track of previous results, and defeat the memory advantages of generators. Perhaps this is erroneous? That said, rewind() should behave consistently. I don't feel it makes sense to have rewind() succeed at one point, and fail at another. It would only cause confusion when not familiar with the behavior. Either allow it, or don't. Not both. Thanks, Aaron Holmes