[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Understanding dotimes skipping by 2
From: |
Eric Abrahamsen |
Subject: |
Re: Understanding dotimes skipping by 2 |
Date: |
Thu, 27 Sep 2018 16:17:23 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Marco Wahl <marcowahlsoft@gmail.com> writes:
> Tim Johnson <tim@akwebsoft.com> writes:
>
>> the following code snippet is as follows:
>> (setq l `(1 2 3 4 5 6 7 8 9 0))
>
>> ;; iterate through a list two elements at a time
>> (let ((x 0))
>> (dotimes (/ (length l) 2)
>> (progn
>> (insert (format "%s %s, " (nth x l) (nth (+ x 1) l)))
>> (setq x (+ x 2)))))
>>
>> ;; and below are the results
>> 1 2, 3 4, 5 6, 7 8, 9 0, nil nil, nil nil, nil nil, nil nil, nil nil, 2
>>
>> I'm confused about the output (nil etc...)which follow the expected numbers.
>> could someone explain?
>> P.S. I get the same output without the `progn form
>
> Looks like "/" is a variable which gets bound to the values of 0 up to
> (length l) and the result of the loop is 2.
>
> It's in the documentation (C-h f dotimes).
To add to that -- if you want to consume a loop two elements at a time,
you'd be better off using `cl-loop' and its "by" keyword.