help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cl-dolist, dolist, cl-return,


From: Barry Margolin
Subject: Re: cl-dolist, dolist, cl-return,
Date: Fri, 10 Jul 2015 14:44:42 -0400
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

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 ***


reply via email to

[Prev in Thread] Current Thread [Next in Thread]