From: AL
Subject: Generating a list of enumerated symbols
Date: 
Message-ID: <1138937280.705972.212550@g47g2000cwa.googlegroups.com>
I'm new to lisp so this may be easy for some of you.

Within a loop, I need to generate symbols such as x0, x1, x2, etc...,
assign each symbol a value, and store them in a list i.e. '(x0 x1 x2)
where x0 = '(1 2 3), x1 = '(4 5 6 7), etc...

I'm really stuck on how to generate the symbols x0, x1, etc...

How can this be done?

Thanks for any help,
AL

From: Raffael Cavallaro
Subject: Re: Generating a list of enumerated symbols
Date: 
Message-ID: <2006020301180616807-raffaelcavallaro@pasdespamsilvousplaitmaccom>
On 2006-02-02 22:28:00 -0500, "AL" <·······@gmail.com> said:

> I'm new to lisp so this may be easy for some of you.
> 
> Within a loop, I need to generate symbols such as x0, x1, x2, etc...,
> assign each symbol a value, and store them in a list i.e. '(x0 x1 x2)
> where x0 = '(1 2 3), x1 = '(4 5 6 7), etc...
> 
> I'm really stuck on how to generate the symbols x0, x1, etc...


CL-USER 1 > (loop for xvar in
                  (let ((varlist (loop for i from 1 to 5 collect 
(gentemp "X")))
                        (values-list (list 'this 'that 'other 'foo 'bar)))
                    (loop for elt in varlist
                          for value in values-list
                          do
                          (setf (symbol-value elt) value)
                          finally (return varlist)))
                  do
                  (format t "~a ~a.~%" (symbol-name xvar) (symbol-value xvar)))
X0 THIS.
X1 THAT.
X2 OTHER.
X3 FOO.
X4 BAR.
NIL
From: AL
Subject: Re: Generating a list of enumerated symbols
Date: 
Message-ID: <1138961612.943885.75210@g44g2000cwa.googlegroups.com>
Thank you both, I now have what I need.
-AL
From: Coby Beck
Subject: Re: Generating a list of enumerated symbols
Date: 
Message-ID: <gGMEf.247082$OU5.139793@clgrps13>
"AL" <·······@gmail.com> wrote in message 
····························@g44g2000cwa.googlegroups.com...
> Thank you both, I now have what I need.

But it is really what you want?  That is, it seems very likely to me that 
there is a better solution to your underlying problem.

-- 
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Raffael Cavallaro
Subject: Re: Generating a list of enumerated symbols
Date: 
Message-ID: <2006020314430650073-raffaelcavallaro@pasdespamsilvousplaitmaccom>
On 2006-02-03 12:46:52 -0500, "Coby Beck" <·····@mercury.bc.ca> said:

> But it is really what you want?  That is, it seems very likely to me 
> that there is a better solution to your underlying problem.

Agreed. If the OP tells us the larger problem he's trying to solve with 
his loop we might be able to suggest a more elegant, lisp-like 
solution. Its worth noting in this connection that the Hyperspec states 
that gentemp is deprecated for the following reason:

"Just because gentemp creates a symbol which did not previously exist 
does not mean that such a symbol might not be seen in the future (e.g., 
in a data file---perhaps even created by the same program in another 
session). As such, this symbol is not truly unique in the same sense as 
a gensym would be. In particular, programs which do automatic code 
generation should be careful not to attach global attributes to such 
generated symbols (e.g., special declarations) and then write them into 
a file because such global attributes might, in a different session, 
end up applying to other symbols that were automatically generated on 
another day for some other purpose."
From: Pascal Bourguignon
Subject: Re: Generating a list of enumerated symbols
Date: 
Message-ID: <87lkwtcay1.fsf@thalassa.informatimago.com>
"AL" <·······@gmail.com> writes:

> I'm new to lisp so this may be easy for some of you.
>
> Within a loop, I need to generate symbols such as x0, x1, x2, etc...,
> assign each symbol a value, and store them in a list i.e. '(x0 x1 x2)
> where x0 = '(1 2 3), x1 = '(4 5 6 7), etc...
>
> I'm really stuck on how to generate the symbols x0, x1, etc...
>
> How can this be done?

Using GENTEMP or GENSYM or MAKE-SYMBOL or INTERN depending on the usage...

From the little you're saying, I'd use GENTEMP.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
From: Thomas A. Russ
Subject: Re: Generating a list of enumerated symbols
Date: 
Message-ID: <ymi4q3cnyj7.fsf@sevak.isi.edu>
"AL" <·······@gmail.com> writes:

This particular question is one that often sets off alarm bells....

> I'm new to lisp so this may be easy for some of you.
> 
> Within a loop, I need to generate symbols such as x0, x1, x2, etc...,
> assign each symbol a value, and store them in a list i.e. '(x0 x1 x2)
> where x0 = '(1 2 3), x1 = '(4 5 6 7), etc...

Why do you want to do this?
What is the larger problem you are working on?
Why do you need the symbols at all?
Perhaps you want to look at hash tables?

> I'm really stuck on how to generate the symbols x0, x1, etc...
> 
> How can this be done?




-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Thomas A. Russ
Subject: Re: Generating a list of enumerated symbols
Date: 
Message-ID: <ymi1wygnyiq.fsf@sevak.isi.edu>
"AL" <·······@gmail.com> writes:

This particular question is one that often sets off alarm bells....

> I'm new to lisp so this may be easy for some of you.
> 
> Within a loop, I need to generate symbols such as x0, x1, x2, etc...,
> assign each symbol a value, and store them in a list i.e. '(x0 x1 x2)
> where x0 = '(1 2 3), x1 = '(4 5 6 7), etc...

Why do you want to do this?
What is the larger problem you are working on?
Why do you need the symbols at all?
Perhaps you want to look at hash tables?

> I'm really stuck on how to generate the symbols x0, x1, etc...
> 
> How can this be done?




-- 
Thomas A. Russ,  USC/Information Sciences Institute