From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Van L Newsgroups: gmane.emacs.help Subject: Re: Understanding dotimes skipping by 2 Date: Fri, 28 Sep 2018 11:29:13 +1000 Message-ID: References: <20180927224840.GA2161@mail.akwebsoft.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1538098077 4788 195.159.176.226 (28 Sep 2018 01:27:57 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 28 Sep 2018 01:27:57 +0000 (UTC) To: Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 28 03:27:53 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g5hZO-00017H-Ew for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Sep 2018 03:27:50 +0200 Original-Received: from localhost ([::1]:40574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5hbU-0005pa-Vn for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Sep 2018 21:30:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5haz-0005pU-OU for Help-gnu-emacs@gnu.org; Thu, 27 Sep 2018 21:29:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5hau-0000q6-RM for Help-gnu-emacs@gnu.org; Thu, 27 Sep 2018 21:29:29 -0400 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:55139) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5hat-0000n0-Ra for Help-gnu-emacs@gnu.org; Thu, 27 Sep 2018 21:29:24 -0400 X-Originating-IP: 220.244.158.222 Original-Received: from epi.local (220-244-158-222.tpgi.com.au [220.244.158.222]) (Authenticated sender: van@scratch.space) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 937FAC0006 for ; Fri, 28 Sep 2018 01:29:18 +0000 (UTC) In-Reply-To: <20180927224840.GA2161@mail.akwebsoft.com> X-Mailer: Apple Mail (2.3124) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.70.183.198 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118044 Archived-At: > the following code snippet is as follows: > (setq l `(1 2 3 4 5 6 7 8 9 0)) > (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))))) >=20 > ;; 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 >=20 > I'm confused about the output (nil etc...)which follow the expected = numbers.=20 > could someone explain? The first argument to dotimes needs a symbol to value binding at a = guess. The character l and 1 are too easy to confuse in reading you might want = to avoid that. (setq q '(1 2 3 4 5 6 7 8 9 0)) (let ((x 0)) (dotimes (i (/ (length q) 2)) (progn (insert (format "%s %s, " (nth x q) (nth (+ x 1) q))) (setq x (+ x 2))))) ; 1 2, 3 4, 5 6, 7 8, 9 0,=20