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 15:32:07 -0800 Organization: AkWebsoft Message-ID: <20180927233207.GB2161@mail.akwebsoft.com> References: <84a7o28rd8.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1538091045 25986 195.159.176.226 (27 Sep 2018 23:30:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 27 Sep 2018 23:30:45 +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 01:30:41 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 1g5fk1-0006hs-Fa for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Sep 2018 01:30:41 +0200 Original-Received: from localhost ([::1]:40302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5fm7-0001zV-Qn for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Sep 2018 19:32:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5flc-0001w2-8A for help-gnu-emacs@gnu.org; Thu, 27 Sep 2018 19:32:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5flT-00079Y-Vh for help-gnu-emacs@gnu.org; Thu, 27 Sep 2018 19:32:17 -0400 Original-Received: from tjohnson.mtaonline.net ([64.4.232.191]:34552) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5flS-00077h-QW for help-gnu-emacs@gnu.org; Thu, 27 Sep 2018 19:32:11 -0400 Original-Received: by linus (Postfix, from userid 1000) id D3900240039; Thu, 27 Sep 2018 15:32:07 -0800 (AKDT) Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <84a7o28rd8.fsf@gmail.com> 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:118041 Archived-At: * Marco Wahl [180927 15:16]: > Tim Johnson 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