[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cl-dolist, dolist, cl-return,
From: |
Emanuel Berg |
Subject: |
Re: cl-dolist, dolist, cl-return, |
Date: |
Sat, 11 Jul 2015 20:52:42 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Barry Margolin <barmar@alum.mit.edu> writes:
>> 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.
That's exactly right!
Very nice - you even put the asterisk with the
variable type and not its name.
I was about to say this discussion is meaningless as
several posts ago it was clear the list isn't
re-evaluated, which was the intuition as well, but now
I've changed my mind, when you put things this way,
please go on.
--
underground experts united
http://user.it.uu.se/~embe8573
- cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/07
- Re: cl-dolist, dolist, cl-return,, John Mastro, 2015/07/07
- Re: cl-dolist, dolist, cl-return,, Stefan Monnier, 2015/07/07
- Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, Stefan Monnier, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, John Mastro, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/09
- Message not available
- Re: cl-dolist, dolist, cl-return,, Barry Margolin, 2015/07/10
- Re: cl-dolist, dolist, cl-return,,
Emanuel Berg <=
- Re: cl-dolist, dolist, cl-return,, Stefan Monnier, 2015/07/10
Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, Pascal J. Bourguignon, 2015/07/07
- Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/08
- RE: cl-dolist, dolist, cl-return,, Drew Adams, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/08
- Message not available
- Re: cl-dolist, dolist, cl-return,, Pascal J. Bourguignon, 2015/07/08