What is happening with this Common Lisp code?

后端 未结 3 2035
野性不改
野性不改 2021-02-20 10:30

I\'ve written the following bit of code to simulate rolling a six-sided die a number of times and counting how many times each side landed up:

(defun dice (num)
         


        
3条回答
  •  再見小時候
    2021-02-20 11:14

    like the post above, the compiler allocates the 0 as constant space. I used to know some tricks for this, one would be make it a macro such:

    `',(list 0 0 0 0 0)
    =>
     ?? (I forget and don't have the other machine on to check)
    

    or wrapped in an (eval-when (compile)) ... )

    also

     (list 0 0 0 0 0) 
    =>
      #.(list 0 0 0 0)
    

    I don't know if this still works (or ever worked). The are also some implentation macros or compiler macros that could help keep the alloaction size constant but the data variable. Don't rememeber off the top of my head anymore.

    remeber to use fill (like bzero in c).

提交回复
热议问题