all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Buchs, Kevin" <buchs.kevin@mayo.edu>
To: <help-gnu-emacs@gnu.org>
Subject: Re: Run a program
Date: Tue, 27 Sep 2011 17:01:14 -0500	[thread overview]
Message-ID: <F326B9A37B353A449FC7A09B36835F82D3CDB2@MACE.sppdg.ad> (raw)

Roland, 

Please consider using some indentation in your code postings, as we are left swimming in the parens if you don't. 

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 
      (  (i n) 
         (repartition [0 0 0])
         (c1 0)
         (c2 0)
         (r 0)) 
  
      (message "repartition starts at: %s " repartition)
      (aset repartition 0 0)
      (aset repartition 1 0)
      (aset repartition 2 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)))

Kevin Buchs   |  Senior Engineer  |  Department of Physiology and Biomedical Engineering - SPPDG
507-538-5459  |   buchs.kevin@mayo.edu  |  http://www.mayo.edu/sppdg
Mayo Clinic  |  200 1st St. SW  |  Rochester, MN 55905  


> (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)))


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))



             reply	other threads:[~2011-09-27 22:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-27 22:01 Buchs, Kevin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-09-27  5:28 Run a program Roland Thiers
2011-09-27 21:06 ` Deniz Dogan
2011-09-28  1:43 ` Le Wang
2011-09-28  9:15   ` Roland Thiers
2011-09-28 13:44     ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F326B9A37B353A449FC7A09B36835F82D3CDB2@MACE.sppdg.ad \
    --to=buchs.kevin@mayo.edu \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.