Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62236 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71367 invoked from network); 18 Aug 2012 10:04:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Aug 2012 10:04:01 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:61652] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B0/25-31572-0986F205 for ; Sat, 18 Aug 2012 06:04:01 -0400 Received: by lahl5 with SMTP id l5so2608205lah.29 for ; Sat, 18 Aug 2012 03:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=QeD7Hu5c/dY2v+qgP4PA5/P0tN4ffvNcpCeYzGWbqLE=; b=D4Uzcw3j9XNYrkWuR6/5QNhPlmyoc/yFvMn5fAUS3mpr5FAAUas24HnBZQ+PX7AzBR t41/D3CVDZ6zCg//yXbyKyvCRC2QfDAno4yd/sukxJCFosFNuKsC3fIaZsmG5VMOQ4cW t4GRlkt7RLHLAHZLB0DgH/gapJ1ZR91+xpmfJkoisysJu3XTmkWg34Q0OUPmy0B7pMg1 /qi8GyCoNiVoeAgwSZ5lPDC+9oIDBctzD3S/mSVR7pM2yubw1K5nQfgfcacVRg5IhmXJ mSdoZbjMT7FCbNOzrgxROQ+byZNEdJaJip7pe+r7KLMuSoHp/BDr/bnD+LsE3pBzstBd M6ZA== MIME-Version: 1.0 Received: by 10.152.113.68 with SMTP id iw4mr7630139lab.50.1345284237787; Sat, 18 Aug 2012 03:03:57 -0700 (PDT) Received: by 10.152.122.51 with HTTP; Sat, 18 Aug 2012 03:03:57 -0700 (PDT) In-Reply-To: <502A91E7.4030204@aaronholmes.net> References: <50280D37.10109@moonspot.net> <502A7FFB.1090502@aaronholmes.net> <502A8CB2.7060708@sugarcrm.com> <502A91E7.4030204@aaronholmes.net> Date: Sat, 18 Aug 2012 12:03:57 +0200 Message-ID: To: Aaron Holmes Cc: Stas Malyshev , "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [RFC] Generators From: nikita.ppv@gmail.com (Nikita Popov) On Tue, Aug 14, 2012 at 7:59 PM, Aaron Holmes wrote: > Thanks for clarifying. It makes sense now, considering foreach's behavior > and the generators statefulness allowing what otherwise seems inconsistent. > However, might it make sense to no-op instead of erroring? If generators > allow rewind(), it would be unexpected to receive an error for calling it. A no-op is the current behavior. The issue with that is that you could accidentally reuse an already depleted (or partially depleted) generator. I.e. you run it through one loop and then through another one. With a no-op rewind it would be hard to figure out what the issue is. The error makes clear that you tried to iterate an already iterated generator. Furthermore, if you indeed *want* to partially traverse a generator in several loops, you can simply wrap it in a NoRewindIterator. This has the additional benefit of making it more clear what you want to do. Nikita