What is happening with this Common Lisp code? -


I have written the following code to simulate the six-sided rolling multiple times to die and how many times each has counted Side landed:

  (defun dice (num) (let (myList '(0 0))) (progn (format t "~ a" myList) (1 for loop To num (but myRand (random 6)) (setf (nth myRand myList) (+ 1 (nth myRand myList)))) (format t "~ a" myList)))   

function works great for the first time when I call it, but the variables on the subsequent calls start at the myList value Confirms that began at the end of the last call, all was as I thought instead to revert to zero should be with the Come statement why this happens?

This is the result of using a continuous list in the initiator:

 < Code> ((myList '(0 0 0)))   

Change that line to:

  (((MyList (list 0 0) 0)))   

And it will behave according to your expectation. The first line results only once in the allocation (because it is a continuous list), but list code> you force the allocation every time you enter the function.

Edit Please: It can be helpful, especially toward the end.

The answer to the question can also be useful.

This loop keyword archive , which collects the results of each walk in the list and gives back as the value of loop . List

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -