From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Deniz Dogan Newsgroups: gmane.emacs.help Subject: Re: Run a program Date: Tue, 27 Sep 2011 23:06:54 +0200 Message-ID: <4E823AEE.8060901@dogan.se> References: <4BB5BAB3-2D48-402A-85EF-070EEC256DB3@canl.nc> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1317157639 22871 80.91.229.12 (27 Sep 2011 21:07:19 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 27 Sep 2011 21:07:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 27 23:07:15 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 1R8erz-0006l8-5o for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Sep 2011 23:07:15 +0200 Original-Received: from localhost ([::1]:50451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8ery-0000GF-IX for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Sep 2011 17:07:14 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:36629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8ers-0000Fr-Tq for help-gnu-emacs@gnu.org; Tue, 27 Sep 2011 17:07:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8err-00079Z-TM for help-gnu-emacs@gnu.org; Tue, 27 Sep 2011 17:07:08 -0400 Original-Received: from ch-smtp04.sth.basefarm.net ([80.76.153.5]:54002) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8err-00079U-OP for help-gnu-emacs@gnu.org; Tue, 27 Sep 2011 17:07:07 -0400 Original-Received: from c80-216-107-100.bredband.comhem.se ([80.216.107.100]:49698 helo=[192.168.0.11]) by ch-smtp04.sth.basefarm.net with esmtp (Exim 4.76) (envelope-from ) id 1R8erj-0003Ds-EM for help-gnu-emacs@gnu.org; Tue, 27 Sep 2011 23:07:01 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 In-Reply-To: <4BB5BAB3-2D48-402A-85EF-070EEC256DB3@canl.nc> X-Originating-IP: 80.216.107.100 X-Scan-Result: No virus found in message 1R8erj-0003Ds-EM. X-Scan-Signature: ch-smtp04.sth.basefarm.net 1R8erj-0003Ds-EM da0055319efbb43175b670e0eac7584c X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.76.153.5 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:82359 Archived-At: On 2011-09-27 07:28, Roland Thiers wrote: > Hi all, > I am a novice programming in Emacs Lisp. > My question : > I dit this program : > (defun coins (n) > (let ((i n) (repartition [0 0 0]) (c1 0) (c2 0) (r 0)) > (while (> i 0) > (setq c1 (random 2)) > (setq c2 (random 2)) > (setq r (+ c1 c2)) > (aset repartition r (1+ (aref repartition r))) > (setq i (- i 1))) > (message " repartition %s " repartition))) > > aim : you toss two coins, count tails : 0 or 1 or 2. Repeat 10 times or > more and see what happens. > > If I evaluate this program with C-x C-e and do (coins 10) C-x C-e it > works fine, I get some thing like > [3 5 2]. > But if I repeat C-x C-e after (coins 10) I get some thing like [5 11 4] > then [9 15 6] ... > I can't understand that ! > Could some one help me ? 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))