From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tim Johnson Newsgroups: gmane.emacs.help Subject: Re: Understanding dotimes skipping by 2 Date: Thu, 27 Sep 2018 18:56:03 -0800 Organization: AkWebsoft Message-ID: <20180928025603.GD2161@mail.akwebsoft.com> References: <20180927224840.GA2161@mail.akwebsoft.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1538103274 3678 195.159.176.226 (28 Sep 2018 02:54:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 28 Sep 2018 02:54:34 +0000 (UTC) User-Agent: Mutt/1.10.0 (2018-05-17) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 28 04:54:29 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 1g5ivF-0000tJ-1H for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Sep 2018 04:54:29 +0200 Original-Received: from localhost ([::1]:40916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5ixL-000543-HO for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Sep 2018 22:56:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5iws-00053y-Hs for help-gnu-emacs@gnu.org; Thu, 27 Sep 2018 22:56:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5iwp-0001q1-9Q for help-gnu-emacs@gnu.org; Thu, 27 Sep 2018 22:56:10 -0400 Original-Received: from tjohnson.mtaonline.net ([64.4.232.191]:40674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5iwp-0001p7-0o for help-gnu-emacs@gnu.org; Thu, 27 Sep 2018 22:56:07 -0400 Original-Received: by linus (Postfix, from userid 1000) id E6EDD240039; Thu, 27 Sep 2018 18:56:03 -0800 (AKDT) Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.4.232.191 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:118045 Archived-At: * Van L [180927 17:39]: > > > 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))))) > > > > ;; 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? > > 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, Good practices tip. Thanks Van .. -- Tim Johnson http://www.tj49.com