From: Tim Johnson <tim@akwebsoft.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Understanding dotimes skipping by 2
Date: Thu, 27 Sep 2018 15:32:07 -0800 [thread overview]
Message-ID: <20180927233207.GB2161@mail.akwebsoft.com> (raw)
In-Reply-To: <84a7o28rd8.fsf@gmail.com>
* Marco Wahl <marcowahlsoft@gmail.com> [180927 15:16]:
> 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).
You've revealed that I have a syntax error in the code above.
`/ was being treated as a variable
I needed an outer parens for the arguments and needed to add a
count variable.
;;
(dotimes (count (/ (length l) 2)) ;; what I'm after (I think)
> HTH
Thanks, helpful indeed
--
Tim Johnson
http://www.tj49.com
next prev parent reply other threads:[~2018-09-27 23:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1418.1538089091.1284.help-gnu-emacs@gnu.org>
2018-09-27 23:14 ` Understanding dotimes skipping by 2 Marco Wahl
2018-09-27 23:17 ` Eric Abrahamsen
2018-09-27 23:59 ` Tim Johnson
2018-09-27 23:32 ` Tim Johnson [this message]
2018-09-27 22:48 Tim Johnson
2018-09-28 1:29 ` Van L
2018-09-28 2:56 ` Tim Johnson
2018-09-28 9:11 ` Joost Kremers
2018-09-28 9:50 ` Van L
2018-09-28 12:23 ` Eli Zaretskii
2018-09-28 12:26 ` Van L
2018-09-28 17:47 ` Tim Johnson
2018-09-28 18:16 ` Noam Postavsky
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=20180927233207.GB2161@mail.akwebsoft.com \
--to=tim@akwebsoft.com \
--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.