<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hi,<br><br>Working in CLM with a .clm file, getting confused with lisp, and I was hoping I could get some help from lisp experts here.<br><br>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? <br><br>I can access the global list by defining a function in ex. 2, but curious where I'm going wrong in ex. 1?<br><br>ex. 1<br><br>(defvar mylist '(0.5 100.0 200.25 4000.0 1.0 0.33))<br><br>(defvar *test* '(nil))<br><br>(loop<br> for i from 0 to 10 by 1<br> for xx in mylist collect (random-element mylist) into *test*<br> finally (return *test*))<br>)<br><br>(loop<br> for i from 0 to 10 by 1<br> for yy in *test* ;the randomized list above does not seem available as global here<br> do<br> (format t " ~A" yy)<br> )<br><br>------------------<br>ex. 2<br><br>(defvar mylist '(0.5 100.0 200.25 4000.0 1.0 0.33))<br><br>(defvar *test* '(nil))<br><br>(defun myfunc (somelist)<br>(loop<br> for i from 0 to 10 by 1<br> for xx in somelist collect (random-element somelist) into *test*<br> finally (return *test*))<br>) <br><br>(loop<br> for i from 0 to 10 by 1<br> for yy in (myfunc mylist)<br> do<br> (format t " ~A" yy)<br> )<br>                                            </div></body>
</html>