From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Buchs, Kevin" Newsgroups: gmane.emacs.help Subject: Re: Run a program Date: Tue, 27 Sep 2011 17:01:14 -0500 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1317160865 11571 80.91.229.12 (27 Sep 2011 22:01:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 27 Sep 2011 22:01:05 +0000 (UTC) To: Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 28 00:01:01 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R8fi1-0002Vo-Cm for geh-help-gnu-emacs@m.gmane.org; Wed, 28 Sep 2011 00:01:01 +0200 Original-Received: from localhost ([::1]:33903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8fi0-0002oE-IQ for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Sep 2011 18:01:00 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:58864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8fhw-0002o9-Al for help-gnu-emacs@gnu.org; Tue, 27 Sep 2011 18:00:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8fhv-00080C-3g for help-gnu-emacs@gnu.org; Tue, 27 Sep 2011 18:00:56 -0400 Original-Received: from mail10.mayo.edu ([129.176.212.47]:36761) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8fhu-0007zv-Ur for help-gnu-emacs@gnu.org; Tue, 27 Sep 2011 18:00:55 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUIAJxGgk6BsNQ1/2dsb2JhbAA+A5k9jkR4gVMBAQEBAzBbAQgiBhgHVwEEEwihcZZSiQGDe4IwYASHQjCLYIoZhzk X-IronPort-AV: E=Sophos;i="4.68,451,1312174800"; d="scan'208";a="110179057" Original-Received: from mhro1a.mayo.edu ([129.176.212.53]) by ironport10.mayo.edu with ESMTP; 27 Sep 2011 17:00:53 -0500 Original-Received: from smtprelay.mayo.edu (smtprelay2.mayo.edu [192.168.48.11]) by mhro1a.mayo.edu with ESMTP id BT-MMP-3834024 for help-gnu-emacs@gnu.org; Tue, 27 Sep 2011 17:00:53 -0500 Original-Received: from MACE.mayo.edu (mace.mayo.edu [129.176.215.134]) by smtprelay.mayo.edu (8.12.11/8.12.11) with ESMTP id p8RM0qGu000451 for ; Tue, 27 Sep 2011 17:00:53 -0500 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Run a program Thread-Index: Acx9YBeJkQqYhUNjTRSRxH2ygWoStA== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 129.176.212.47 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:82360 Archived-At: Roland,=20 Please consider using some indentation in your code postings, as we are = left swimming in the parens if you don't.=20 It is also inexplicable by me that repartition is maintaining a value, = despite the let form. It is not recognized globally. You can see that = with the additional message form I inserted. Then in addition, I did = explicit initialization of each element. (defun coins (n) (let=20 ( (i n)=20 (repartition [0 0 0]) (c1 0) (c2 0) (r 0))=20 =20 (message "repartition starts at: %s " repartition) (aset repartition 0 0) (aset repartition 1 0) (aset repartition 2 0) (while (> i 0)=20 (setq c1 (random 2))=20 (setq c2 (random 2)) (setq r (+ c1 c2)) (aset repartition r (1+ (aref repartition r)))=20 (setq i (- i 1)))=20 (message " repartition %s " repartition))) Kevin Buchs=A0=A0 |=A0=A0Senior Engineer | Department of Physiology = and Biomedical Engineering - SPPDG 507-538-5459=A0=A0|=A0=A0=A0buchs.kevin@mayo.edu | = =A0http://www.mayo.edu/sppdg Mayo Clinic=A0=A0|=A0=A0200 1st St. SW=A0 |=A0 Rochester, MN 55905=A0=20 > (defun coins (n) > (let ((i n) (repartition [0 0 0]) (c1 0) (c2 0) (r 0)) (while (> i 0)=20 > (setq c1 (random 2)) (setq c2 (random 2)) (setq r (+ c1 c2)) (aset=20 > repartition r (1+ (aref repartition r))) (setq i (- i 1))) (message "=20 > repartition %s " repartition))) I am not exactly sure why that happens, but it seems like you're = referencing the same vector after each call. To make sure the vector is = fresh before each run, replace: (repartition [0 0 0]) with: (repartition (make-vector 3 0))