all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: emacs-devel@gnu.org
Subject: dolist considered harmful
Date: Tue, 30 Oct 2018 14:39:46 -0400	[thread overview]
Message-ID: <jwvwopzfftn.fsf-monnier+emacs@gnu.org> (raw)

All this pcase-dolist discussion made me take a second look at dolist
and now I wondering whether we should keep it:

- The docstring is incomprehensible:

      Loop over a list.
      Evaluate BODY with VAR bound to each car from LIST, in turn.
      Then evaluate RESULT to get return value, default nil.

  I don't know how to loop over a list.  Did they mean to set the cdr
  of the last element so it loops back to the first element?
  "evaluate" is unclear (is it passed to   `eval`?  Then why not say it?
  What second arg is passed to `eval`?).
  but why evaluate it several times?
  Also, in which order?
  How does RESULT communicate the return value?
  Is it RESULT which defaults to nil or the return value?
  If the return value, then when does it default to nil?

- The docstring says nothing of what happens when LIST is not a list,
  yet a quick grep shows that most uses of dolist use for LIST a simple
  variable rather than a list.  What gives?

Since it can only be used when we're 100% sure that LIST is a LIST,
(and who can be sure of such a thing in a dynamic language like Emacs
Lisp), I think we'd be better off deprecating it and changing all uses
of dolist with a clear while+cdr loop that everyone can understand.


        Stefan



             reply	other threads:[~2018-10-30 18:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30 18:39 Stefan Monnier [this message]
2018-10-30 19:31 ` dolist considered harmful Eli Zaretskii
2018-10-30 23:24 ` Jay Kamat
2018-10-30 23:29   ` Noam Postavsky
2018-10-30 23:47     ` Drew Adams
2018-10-31 22:02 ` Garreau, Alexandre
2018-10-31 22:44   ` Noam Postavsky
2018-10-31 23:01     ` Garreau, Alexandre

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=jwvwopzfftn.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /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.