[CM] defvar global list

James Hearon j_hearon at hotmail.com
Fri Dec 26 11:19:35 PST 2014


Hi,

Working in CLM with a .clm file, getting confused with lisp, and I was hoping I could get some help from lisp experts here.

I'm confused why collecting into a global list is not available from the second loop, in ex. 1.  I'm wondering if I'm not understanding something about scope.  Should the loops from ex. 1 be wrapped with something else like a "let" statement? 

I can access the global list by defining a function in ex. 2, but curious where I'm going wrong in ex. 1?

ex. 1

(defvar mylist '(0.5  100.0  200.25  4000.0  1.0  0.33))

(defvar *test* '(nil))

(loop
   for i from 0 to 10  by 1
   for xx in mylist collect (random-element mylist) into *test*
   finally (return *test*))
)

(loop
   for i from 0 to 10 by 1
   for yy in *test*  ;the randomized list above does not seem available as global here
   do
     (format t " ~A" yy)
 )

------------------
ex. 2

(defvar mylist '(0.5  100.0  200.25  4000.0  1.0  0.33))

(defvar *test* '(nil))

(defun myfunc (somelist)
(loop
   for i from 0 to 10  by 1
   for xx in somelist collect (random-element somelist) into *test*
   finally (return *test*))
) 

(loop
   for i from 0 to 10 by 1
     for yy in (myfunc mylist)
   do
     (format t " ~A" yy)
 )
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ccrma-mail.stanford.edu/mailman/private/cmdist/attachments/20141226/3ecd9dd8/attachment.html 


More information about the Cmdist mailing list