From: Tino Calancha <tino.calancha@gmail.com>
To: Philipp Stephani <p.stephani2@gmail.com>
Cc: Marcin Borkowski <mbork@mbork.pl>,
Tino Calancha <tino.calancha@gmail.com>,
26338@debbugs.gnu.org, npostavs@users.sourceforge.net,
Juri Linkov <juri@linkov.net>
Subject: bug#26338: 26.0.50; Collect all matches for REGEXP in current buffer
Date: Sun, 9 Apr 2017 00:20:22 +0900 (JST) [thread overview]
Message-ID: <alpine.DEB.2.20.1704090009500.20978@calancha-pc> (raw)
In-Reply-To: <CAArVCkQpD4YQwpb8e0yDEEjFqYdt9WWKcgVAdXwxeLjqbWCWXg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4868 bytes --]
On Sat, 8 Apr 2017, Philipp Stephani wrote:
>
>
> Tino Calancha <tino.calancha@gmail.com> schrieb am Sa., 8. Apr. 2017 um 15:42 Uhr:
>
>
> On Sat, 8 Apr 2017, Philipp Stephani wrote:
>
> >
> >
> > Tino Calancha <tino.calancha@gmail.com> schrieb am Sa., 8. Apr. 2017 um 06:46 Uhr:
> >
> >
> > On Fri, 7 Apr 2017, Drew Adams wrote:
> >
> > >>> Or an addition to cl-loop that would allow doing something like
> > >>>
> > >>> (cl-loop for m being the matches of "foo\\|bar"
> > >>> do ...)
> > >>>
> > >>> Then you could easily 'collect m' to get the list of matches if you want
> > >>> that.
> > >>
> > >> Your proposals looks nice to me ;-)
> > >
> > > (Caveat: I have not been following this thread.)
> > >
> > > I think that `cl-loop' should be as close to Common Lisp `loop'
> > > as we can reasonably make it. We should _not_ be adding other
> > > features to it or changing its behavior away from what it is
> > > supposedly emulating.
> > >
> > > If you want, create a _different_ macro that is Emacs-specific,
> > > with whatever behavior you want. Call it whatever you want
> > > that will not be confused with Common Lisp emulation.
> > >
> > > Please keep `cl-' for Common Lisp emulation. We've already
> > > seen more than enough tampering with this - people adding
> > > their favorite thing to the `cl-' namespace. Not good.
> > Drew, i respect your opinion; but so far the change
> > would just extend `cl-loop' which as you noticed has being already
> > extended before.
> > For instance, we have:
> > cl-loop for x being the overlays/buffers ...
> >
> > Don't see a problem to have those things.
> >
> >
> > I do. They couple the idea of an iterable with a looping construct, and such coupling is bad for various reasons:
> > - Coupling of unrelated entities is always an antipattern.
> > - For N iterables and M looping constructs, you need to implement N*M integrations.
> > Instead this should use an iterable, e.g. a generator function (iter-defun). cl-loop supports these out of the box.
> Then, you don't like (as Drew, but for different reasons) that we have:
> cl-loop for x being the buffers ...
>
>
> I don't like it, but it's there and cannot be removed for compatibility reasons, so I'm not arguing about it. I'm arguing against
> adding more such one-off forms.
I see. Thanks for the clarification.
>
>
> but it seems you are fine having iter-by clause in cl-loop, which seems an
> Emacs extension (correctme if i am wrong). So in principle, you are happy
> with adding useful extensions to CL, not just keep it an emulation as
> Drew wants.
>
>
> Yes, I don't care about Common Lisp. The iter-by clause is less of a problem than 'buffers' etc. because it's not a one-off that
> couples a looping construct with some random semantics.
Some people like it and refer about that as the 'expressivity' of the loop
facility. I guess it's a matter of taste, don't need to use such
constructs if you don't like it. Some people do.
>
> 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.
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.
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)
next prev parent reply other threads:[~2017-04-08 15:20 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-02 12:41 bug#26338: 26.0.50; Collect all matches for REGEXP in current buffer Tino Calancha
2017-04-02 15:57 ` Dmitry Gutov
2017-04-03 3:58 ` Tino Calancha
2017-04-02 22:10 ` Juri Linkov
2017-04-03 4:01 ` Tino Calancha
2017-04-03 6:13 ` Tino Calancha
2017-04-03 23:35 ` Juri Linkov
2017-04-04 1:37 ` Tino Calancha
2017-04-04 2:20 ` Tino Calancha
2017-04-04 14:32 ` Marcin Borkowski
2017-04-05 11:58 ` Tino Calancha
2017-04-05 13:11 ` npostavs
2017-04-07 10:06 ` Tino Calancha
2017-04-07 14:40 ` Drew Adams
2017-04-08 4:45 ` Tino Calancha
2017-04-08 5:49 ` Drew Adams
2017-04-08 15:29 ` Tino Calancha
2017-04-08 15:42 ` Drew Adams
2017-04-08 11:46 ` Philipp Stephani
2017-04-08 13:42 ` Tino Calancha
2017-04-08 14:41 ` Philipp Stephani
2017-04-08 15:20 ` Tino Calancha [this message]
2017-04-22 19:42 ` Philipp Stephani
2017-04-08 15:38 ` npostavs
2017-04-22 19:36 ` Philipp Stephani
2017-04-05 22:03 ` Juri Linkov
2017-04-07 14:47 ` Tino Calancha
2017-04-07 15:28 ` Noam Postavsky
2017-04-07 15:54 ` Drew Adams
2017-04-08 13:49 ` Tino Calancha
2020-09-15 15:41 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1704090009500.20978@calancha-pc \
--to=tino.calancha@gmail.com \
--cc=26338@debbugs.gnu.org \
--cc=juri@linkov.net \
--cc=mbork@mbork.pl \
--cc=npostavs@users.sourceforge.net \
--cc=p.stephani2@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.