[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dolist considered harmful
From: |
Eli Zaretskii |
Subject: |
Re: dolist considered harmful |
Date: |
Tue, 30 Oct 2018 21:31:18 +0200 |
> From: Stefan Monnier <address@hidden>
> Date: Tue, 30 Oct 2018 14:39:46 -0400
>
> - 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.
I think the rest of the doc string explains how.
> "evaluate" is unclear (is it passed to `eval`? Then why not say it?
What "evaluation" is, is described in the section "Evaluation" of the
ELisp manual.
> Also, in which order?
It says "each car from LIST, in turn". I think this answers your
question.
> 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?
I think this is clear from the text, I'm unsure what confused you.
> - 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?
There's no contradiction here.
> 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.
Patches welcome.