[CM] defvar global list

Orm Finnendahl orm.finnendahl at selma.hfmdk-frankfurt.de
Thu Jan 1 04:21:46 PST 2015


Hi James,

 just as a note: If you are modifying global variables it might be a
good idea to do that explicitely in the outer context (to enhance
readability of the semantics and to avoid explicit local variables).

Your example would change to:

(setf *test*
  (loop for i below 10 collect (random-element mylist)))

Formatting this could be boiled down to:

(format t "~{~A~^ ~}" *test*)

All the best for 2015 to all!
Orm


Am Montag, den 29. Dezember 2014 um 03:42:40 Uhr (+0000) schrieb James Hearon:
> Hi,
> Thank you folks for the hints.  I think I may have it working now using setf.
> 
> (defun random-element (list)
>   (nth (random (length list)) list))
> 
> (defvar mylist '(0.5  100.0  200.25  4000.0 1.0  0.33 0.1 0.2 5000.0 2.0))
> 
> (defvar *test* '(nil))  ;global list
> 
> (loop
>    for i from 0 to 9  by 1
>         for xx in mylist collect (random-element mylist) into atest ;collect into local list
>     finally  (setf *test* atest) ;setf local list to global one
>      )
> 
> (loop
>    for i from 0 to 9  by 1
>      for xx in *test*  ;access global list
>    do
>      (format t " ~A" xx)
>   )
>  		 	   		  

> _______________________________________________
> Cmdist mailing list
> Cmdist at ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist



More information about the Cmdist mailing list