From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.bugs Subject: bug#26338: 26.0.50; Collect all matches for REGEXP in current buffer Date: Sat, 22 Apr 2017 19:42:15 +0000 Message-ID: References: <8737dr6kxx.fsf@calancha-pc> <87h926cvgl.fsf@localhost> <87k272ow7g.fsf@calancha-pc> <87fuhpcbem.fsf@localhost> <87lgrheyvn.fsf@calancha-pc> <87pogsmefn.fsf@jane> <874ly3vw1p.fsf@users.sourceforge.net> <943bd0fd-c4ad-48f4-a803-f832b5bf0edf@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114cb0dcdd4cf6054dc6925c X-Trace: blaine.gmane.org 1492890195 18676 195.159.176.226 (22 Apr 2017 19:43:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 22 Apr 2017 19:43:15 +0000 (UTC) Cc: 26338@debbugs.gnu.org, npostavs@users.sourceforge.net, Marcin Borkowski , Juri Linkov To: Tino Calancha Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 22 21:43:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1d20w1-0004ix-Jd for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Apr 2017 21:43:09 +0200 Original-Received: from localhost ([::1]:36673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d20w7-0004rH-7w for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Apr 2017 15:43:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d20vz-0004rA-LK for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2017 15:43:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d20vu-0000Tg-K1 for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2017 15:43:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36532) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d20vu-0000Ta-EO for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2017 15:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d20vu-00011u-7q for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2017 15:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philipp Stephani Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Apr 2017 19:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26338 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26338-submit@debbugs.gnu.org id=B26338.14928901543923 (code B ref 26338); Sat, 22 Apr 2017 19:43:02 +0000 Original-Received: (at 26338) by debbugs.gnu.org; 22 Apr 2017 19:42:34 +0000 Original-Received: from localhost ([127.0.0.1]:34731 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d20vR-00011D-Mw for submit@debbugs.gnu.org; Sat, 22 Apr 2017 15:42:33 -0400 Original-Received: from mail-wm0-f48.google.com ([74.125.82.48]:34968) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d20vQ-000111-29 for 26338@debbugs.gnu.org; Sat, 22 Apr 2017 15:42:32 -0400 Original-Received: by mail-wm0-f48.google.com with SMTP id w64so36733439wma.0 for <26338@debbugs.gnu.org>; Sat, 22 Apr 2017 12:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kdp9SjjLn9mOz23MU6oVnhQt5Y6t82oWrcQFc/ytYEQ=; b=cUO743oxI/wB4B9ogDfZM2lztt3ED3zqkuvoqSssJaREVbZszXYCKoDO3aONW4p8JG ERb7JUb+AX4T++PyCIfOtrrxNI1++5YAOQO6NsUWqsJv+9bFXsUNEbTIL7FfP6ghS8jo gy6SI9XItbFWnqZlqF9+Y7ourTf/ZbtPtZ7xPFSULouCqhKMw/ryQPek26HkvL6A+Qp9 8sRISuNDrWp9WsdBfrzTAvsFaKZJjrWPQeXosFhIJ4NW6wX5RAEz+10537isHU2UQReV QDCzY5MWsLikUm0Q7MHrovp4zykL9pXRKGrFfklLlN58E7gYH+F1LaI7nbQ0SLuZwueE 9nHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kdp9SjjLn9mOz23MU6oVnhQt5Y6t82oWrcQFc/ytYEQ=; b=DcKEzQc5MFGwCmsTL6EOUxDCG9XYkgRzyEA3tjOPcElnlrJbnp377bXppA70tdMgq2 9QTqWuFVtfTRqZUwKEY+Ai/Y4od4PUreW//BaSsz8aS4evTP5yW2GFKBtC1Ew0rpnxmq SjE5J4bVp9sUgxlBgmFMxL7mbnuH/qXmgUWUChiFIg6JUs5yX6Nr4DzPIXnU+2fStNEw pVCQxoBEi7cwXKzViVKcOThcnR2WhQy2z0AE+uwBmpkv1oTR1lHehiPHBVFjcGrzL2rO EhCZc7WcgkdRhEwVjWuusLyMGqB58wrWuA6N7V5JpTCUrJJliSjFAHFwx5513UJCXt0f KkMQ== X-Gm-Message-State: AN3rC/5PggZZ2SrY2rb642oS1f+/WxQXiR2BPKmtufGN6HtzhA2n6c/X 9DQWCFFkny4DmqaVdXc42bQnaa1yPA== X-Received: by 10.28.161.66 with SMTP id k63mr3937389wme.46.1492890146390; Sat, 22 Apr 2017 12:42:26 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:131891 Archived-At: --001a114cb0dcdd4cf6054dc6925c Content-Type: text/plain; charset=UTF-8 Tino Calancha schrieb am Sa., 8. Apr. 2017 um 17:20 Uhr: > > > > > Your point is about performance. > > > > > > No, I care mostly about clarity, simplicity, and good API design, > including separation of concerns. > Expressibity and readability might be some kind of clarity. > Yes, but it seems we mean different things with these words. "Readability" for me means (among other things) that each logical entity has a single purpose. The single purpose of the (already way too complex) cl-loop macro is iterating over things. It doesn't concern itself with the things it should iterate over and where they come from. > I totally agree about API design and separation of concerns. > > > > I am driven by easy to write code. > > Maybe you can provide an example about how to write those things > using > > the iter-by cl-loop clause. > > > > > > Sure: > > (require 'generator) > > (iter-defun re-matches (regexp) > > (while (re-search-forward regexp nil t) > > (iter-yield (match-string 0)))) > > (iter-do (m (re-matches (rx digit))) > > (print m)) > > (cl-loop for m iter-by (re-matches (rx digit)) > > do (print m)) > Thank you very much for your examples. They are nice. I am not > as familiar as you with generators. I must study them more. > > Between A) and B), the second looks at least as simple and clear as > the first one, and probably more readable. > I disagree. (A) clearly separates the generation of the stream of objects to iterate over from the iteration, (B) doesn't. (A) is extensible to any kind of iteration as long as it can be expressed using generators (or lists, vectors, ...), while for (B) you need a new keyword for every new thing to iterate over. > > A) > (iter-defun re-matches (regexp) > (while (re-search-forward regexp nil t) > (iter-yield (match-string-no-properties 1)))) > > (cl-loop for m iter-by (re-matches "^(defun \\(\\S +\\)") > collect m) > > B) > (cl-loop for m the matches of "^(defun \\(\\S +\\)" > collect m) --001a114cb0dcdd4cf6054dc6925c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


Tino C= alancha <tino.calancha@gmail.= com> schrieb am Sa., 8. Apr. 2017 um 17:20=C2=A0Uhr:

>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0Your point is about performance.
>
>
> No, I care mostly about clarity, simplicity, and good API design, incl= uding separation of concerns.
Expressibity and readability might be some kind of clarity.

Yes, but it seems we mean different things with these = words. "Readability" for me means (among other things) that each = logical entity has a single purpose. The single purpose of the (already way= too complex) cl-loop macro is iterating over things. It doesn't concer= n itself with the things it should iterate over and where they come from.
=C2=A0
I totally agree about API design and separation of concerns.
> =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0 I am driven by easy to write code. >=C2=A0 =C2=A0 =C2=A0 =C2=A0Maybe you can provide an example about how t= o write those things using
>=C2=A0 =C2=A0 =C2=A0 =C2=A0the iter-by cl-loop clause.
>
>
> Sure:
> =C2=A0(require 'generator)
> (iter-defun re-matches (regexp)
> =C2=A0 (while (re-search-forward regexp nil t)
> =C2=A0 =C2=A0 (iter-yield (match-string 0))))
> (iter-do (m (re-matches (rx digit)))
> =C2=A0 (print m))
> (cl-loop for m iter-by (re-matches (rx digit))
> do (print m))
Thank you very much for your examples.=C2=A0 They are nice.=C2=A0 I am not<= br> as familiar as you with generators.=C2=A0 I must study them more.

Between A) and B), the second looks at least as simple and clear as
the first one, and probably more readable.

<= div>I disagree. (A) clearly separates the generation of the stream of objec= ts to iterate over from the iteration, (B) doesn't. (A) is extensible t= o any kind of iteration as long as it can be expressed using generators (or= lists, vectors, ...), while for (B) you need a new keyword for every new t= hing to iterate over.
=C2=A0

A)
(iter-defun re-matches (regexp)
=C2=A0 =C2=A0(while (re-search-forward regexp nil t)
=C2=A0 =C2=A0 =C2=A0(iter-yield (match-string-no-properties 1))))

(cl-loop for m iter-by (re-matches "^(defun \\(\\S +\\)")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 collect m)

B)
(cl-loop for m the matches of "^(defun \\(\\S +\\)"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 collect m)
--001a114cb0dcdd4cf6054dc6925c--