From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Gnu Elpa: stream.el: Add some more basic stream operations Date: Thu, 02 Mar 2017 23:38:24 +0100 Message-ID: <87efyf1ezj.fsf@drachen> References: <87twhbmwbx.fsf@web.de> <878tynl720.fsf@petton.fr> <8737onlapw.fsf@web.de> <87ziqu7ew9.fsf@petton.fr> <87mvmuxuyo.fsf@web.de> <8760tixi99.fsf@web.de> <87twh1kpem.fsf@web.de> <87y42r4d3a.fsf@web.de> <878tug9eh3.fsf@web.de> <87a8es6dcq.fsf@web.de> <87bmz7517d.fsf@web.de> <87shmw76cm.fsf@drachen> <8737evltxs.fsf@petton.fr> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1488494327 14558 195.159.176.226 (2 Mar 2017 22:38:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 2 Mar 2017 22:38:47 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: Emacs developers , Yuri Khan To: Nicolas Petton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 02 23:38:42 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjZMt-00032Y-JY for ged-emacs-devel@m.gmane.org; Thu, 02 Mar 2017 23:38:39 +0100 Original-Received: from localhost ([::1]:55035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjZMz-0001aE-Dd for ged-emacs-devel@m.gmane.org; Thu, 02 Mar 2017 17:38:45 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjZMr-0001a8-IW for emacs-devel@gnu.org; Thu, 02 Mar 2017 17:38:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjZMm-0001lE-K1 for emacs-devel@gnu.org; Thu, 02 Mar 2017 17:38:37 -0500 Original-Received: from mout.web.de ([212.227.15.4]:58007) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cjZMm-0001k9-9u for emacs-devel@gnu.org; Thu, 02 Mar 2017 17:38:32 -0500 Original-Received: from drachen.dragon ([109.43.3.114]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Mg1Nl-1cyBwU0p2D-00NTLE; Thu, 02 Mar 2017 23:38:27 +0100 In-Reply-To: <8737evltxs.fsf@petton.fr> (Nicolas Petton's message of "Thu, 02 Mar 2017 13:55:11 +0100") X-Provags-ID: V03:K0:Ltbm3CrSvikdpQ3qG/wPQpTtyHKAbR3e7HMKn56nYB7qKt8ZqZO MkDlV1/w405MOwwtKbgPmwfj4lor8i6O7+aQboZ0XuYDSKXzCzQbJwvcmOJkiY4OVDpsEpY 4yJucRQzHr0NoUd3qx3bWomCZ5ExYRlqsWD6iOyrFEvaz78OwY7jqRkLTEYvUyPsPQnoo0n Uu9eAxSwC5nRyXGm24JWA== X-UI-Out-Filterresults: notjunk:1;V01:K0:UTUMQdTV5W8=:VAgecwiYrrUYOsTT2z7WrX +lc7U30cj8MOkaoBhpv8vUcEoPeQQR0m2tu3H0Fr1cQYrEIyPHPjtVWR5BJI912VmeAtUVm/6 bOtWkrbX/IhRe4MPFyP+8pBdsM7SsEoAyo1i2HQZ1ysGYKemiUkNwy40fri7j3Bnvvek7KBLx N65kaDURXPDmz6yEYHV6rZ4CHEYlcr5QV035te2hm+BMOX6PfezuI9bHAQZOsamPXI2QhOHCh OLLVdmZpBnzGy2KS9E0aKfwZ2oGuj6/mddHlQvkG9M2X+Dw4qGOP2f1AshUDvKxQoLrUgAaa9 g58AXc6xnOVKUapN3poWtvykqrIdKHG1s0m/H8AhW7FDUB1PnVe+UJ4+OJn5Aag0nXaDO7Fx1 ARdL2B0nutxe7enynDmktF6OcsMJuNULQFXv+zoi4wYehvW7IBwhFyGzzkjxij2WKyV8/DJN6 kKoUeNjQqTJ+xWUfr5R+0w828lttYfNUKaCwJidUOfikQq4oPuWSQvh75GsApkk9E6Qcd3Hno QDSbfs36SxDpgzNvPlWcP/kUYZZJySxgKWsar3eQATCVeQxofCjziwRnpppOIWnjeFbFny0s1 WWERbfmwyfPwlRckzlT0g9VJj19MLP/OZxmFC5g4v5pZ0YpjXvENTTLBUrnKVRlfBUZhy/kYW T9w9mG6kWRIxyg88sfumCnPz69ZK2lDettVZlzphpOpL0ksDrnbzxOCShQeMmhvHbw8ZUt9lA 3foGSc73Yt7VJsCRZDxM8aVMP2AVWFDYOl9ehKDoTSi3wAGxcSs0MojsfP73sbRbjTaMvr0O X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.15.4 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:212722 Archived-At: Nicolas Petton writes: > > And this is how that looks. WDYT? > > > > (defun stream-divide-with-get-rest-fun (stream get-rest-fun) > > Is this function public on purpose? > > > (defun stream-partition-with-get-rest-fun (stream get-rest-fun) > > Same question :) Yes, it's public on purpose. They have ugly names (maybe we find better ones?), but they are useful per se as the more general tool. I think they are also quite nice to use, because the creation of streams is factored out, and you can pass the essence of the calculation as a function argument. And `stream-divide' and `stream-partition' no doubt don't cover all use cases one can think of. Looking at two subsequent elements at the same time as in `stream-divide' gives you flexibility, but the first part of `stream-divide' will always have at least one element. This will not fit in some cases. Here is another use case where I think `stream-divide-with-get-rest-fun' suits better: I want to have the last 3 Fibonacci number less than 1000. This is how I would do it: #+begin_src emacs-lisp ;; -*- lexical-binding: t -*- (let ((count 3) fibs) (setq fibs (stream-make (cons 1 (stream-scan #'+ 1 fibs)))) (seq-into-sequence (seq-take (cadr (stream-divide-with-get-rest-fun fibs (lambda (stream) (let ((rest stream)) (dotimes (_ count) (stream-pop stream)) (while (< (stream-pop stream) 1000) (stream-pop rest)) rest)))) count))) #+end_src You could also do the same with `stream-divide', but it would rather look more complicated. Michael.