all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: cl-dolist, dolist, cl-return,
Date: Fri, 10 Jul 2015 14:44:42 -0400	[thread overview]
Message-ID: <barmar-0A47F0.14444210072015@88-209-239-213.giganet.hu> (raw)
In-Reply-To: mailman.6636.1436479362.904.help-gnu-emacs@gnu.org

In article <mailman.6636.1436479362.904.help-gnu-emacs@gnu.org>,
 Emanuel Berg <embe8573@student.uu.se> wrote:

> The reason I asked is the C for loop, which looks like
> this in C99 style:
> 
>     for (int i = 0; i < a_size; i++) { a[i] = ... ; }
> 
> But sometimes, people are tempted to do like this:
> 
>     for (int i = 0; i < sizeof(a)/sizeof(a[0]); i++) {
>        a[i] = ... ;
>     }

You're making the wrong analogy. The list parameter of dolist is 
equivalent to the initialization part of the "for", not the repetition 
or update parts. So if you did:

for (int i = func(x); ...)

you wouldn't expect func(x) to be called every time through the loop, 
would you?

The C equivalent of dolist is:

for (list_ptr* p = <list expr>; p; p = p->next) {
 ...
}

As above, you wouldn't expect <list expr> to be evaluated each time.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


  parent reply	other threads:[~2015-07-10 18:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08  0:14 cl-dolist, dolist, cl-return, Emanuel Berg
2015-07-08  0:31 ` John Mastro
2015-07-08  3:09   ` Stefan Monnier
2015-07-08 10:25     ` Emanuel Berg
2015-07-08 14:44       ` Stefan Monnier
2015-07-08 23:19         ` Emanuel Berg
2015-07-09  1:49           ` John Mastro
2015-07-09 22:00             ` Emanuel Berg
     [not found]             ` <mailman.6636.1436479362.904.help-gnu-emacs@gnu.org>
2015-07-10 18:44               ` Barry Margolin [this message]
2015-07-11 18:52                 ` Emanuel Berg
2015-07-10 16:57           ` Stefan Monnier
2015-07-08 10:23   ` Emanuel Berg
     [not found] <mailman.6511.1436314595.904.help-gnu-emacs@gnu.org>
2015-07-08  3:25 ` Pascal J. Bourguignon
2015-07-08 10:17   ` Emanuel Berg
2015-07-08 14:02     ` Drew Adams
2015-07-08 23:10       ` Emanuel Berg
     [not found]       ` <mailman.6588.1436397019.904.help-gnu-emacs@gnu.org>
2015-07-08 23:56         ` Pascal J. Bourguignon

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=barmar-0A47F0.14444210072015@88-209-239-213.giganet.hu \
    --to=barmar@alum.mit.edu \
    --cc=help-gnu-emacs@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.