[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Run a program
From: |
Buchs, Kevin |
Subject: |
Re: Run a program |
Date: |
Tue, 27 Sep 2011 17:01:14 -0500 |
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))
- Run a program, Roland Thiers, 2011/09/27
- Re: Run a program,
Buchs, Kevin <=