From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani
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.
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)