From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] add SRFI: srfi-121; generators Date: Mon, 01 Jul 2019 01:06:02 -0400 Message-ID: <871rzaibt1.fsf@netris.org> References: <3fb6ac24483457821130185b0e1f277c@disroot.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="169783"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: guile-devel@gnu.org To: nly@disroot.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jul 01 07:06:38 2019 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hhoWT-000i4S-Qj for guile-devel@m.gmane.org; Mon, 01 Jul 2019 07:06:37 +0200 Original-Received: from localhost ([::1]:47822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhoWS-0004iS-P8 for guile-devel@m.gmane.org; Mon, 01 Jul 2019 01:06:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33015) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhoWN-0004iI-35 for guile-devel@gnu.org; Mon, 01 Jul 2019 01:06:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhoWI-0007jO-5p for guile-devel@gnu.org; Mon, 01 Jul 2019 01:06:28 -0400 Original-Received: from world.peace.net ([64.112.178.59]:42630) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hhoWF-0007df-OR for guile-devel@gnu.org; Mon, 01 Jul 2019 01:06:26 -0400 Original-Received: from mhw by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hhoWB-0003e9-ED; Mon, 01 Jul 2019 01:06:19 -0400 In-Reply-To: <3fb6ac24483457821130185b0e1f277c@disroot.org> (nly's message of "Mon, 01 Jul 2019 00:09:08 +0000") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.112.178.59 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19998 Archived-At: Hi Amar, > SRFI-121 Generators. > > All tests(49/49) are passing in my testing. I am not sure if the tests > file is put in the correct place. > > From 0352f9be13aba1e8acc9a8f700f3673334d48d28 Mon Sep 17 00:00:00 2001 > From: Amar Singh > Date: Mon, 1 Jul 2019 05:14:53 +0530 > Subject: [PATCH] add SRFI: srfi-121; generators Thank you for this, but I'm sorry to say that I'm not inclined to add this implementation of SRFI-121 to Guile. The first sentence of SRFI-121's "Rationale" section states: The main purpose of generators is high performance. and I agree. In fact, I would strongly discourage its use except in cases where efficiency demands it. Like hash tables, generators are fundamentally imperative constructs, and they will tend to force code built with them to be written in an imperative style. With this in mind, if SRFI-121 is to be added to Guile, it should be a high performance implementation. The implementation that you provided, which I guess is primarily taken from the sample implementation, is far too inefficient, at least on Guile. Also, the provided implementations of 'generator-find', 'generator-any' and 'generator-every' are incorrect: > +;; generator-find > +(define (generator-find pred g) > + (let loop ((v (g))) > + ; A literal interpretation might say it only terminates on #eof if (pred #eof) but I think this makes more sense... > + (if (or (pred v) (eof-object? v)) > + v > + (loop (g))))) The SRFI says: Returns the first item from the generator gen that satisfies the predicate pred, or #f if no such item is found before gen is exhausted. This specification is quite clear that #f should be returned if EOF is encountered (i.e. "gen is exhausted"). Here, you are returning EOF in that case, which is incorrect. Also, I think that 'pred' should never be applied to EOF. > +;; generator-any > +(define (generator-any pred g) > + (let loop ((v (g))) > + (if (eof-object? v) > + #f > + (if (pred v) > + #t > + (loop (g)))))) This is incorrect. If (pred v) returns a true value, the value returned by (pred v) should be returned, not #t. > +;; generator-every > +(define (generator-every pred g) > + (let loop ((v (g))) > + (if (eof-object? v) > + #t > + (if (pred v) > + (loop (g)) > + #f ; the spec would have me return #f, but I think it must simply be wrong... > + )))) I can't make sense of the comment above. Anyway, this is also incorrect. The specification is clear that if the generator is exhausted after returning some items, (pred LAST-ITEM) should be returned. The only case where #t is returned is if the generator was exhausted before calling 'generator-every'. I might write my own implementation of SRFI-121 from scratch and add it to Guile. Regards, Mark