Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Generating a list of enumerated symbols

27 views
Skip to first unread message

WJ

unread,
Mar 28, 2015, 7:29:50 PM3/28/15
to
Raffael Cavallaro wrote:

> > 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.

Gauche Scheme:

(define x #(this that other foo bar))
(dotimes (i (vector-length x))
(print #"x~i ~(ref x i)."))

x0 this.
x1 that.
x2 other.
x3 foo.
x4 bar.

tar...@google.com

unread,
Mar 30, 2015, 12:57:33 PM3/30/15
to
This doesn't solve the problem as originally stated.

x0 needs to have the value 'this, and there is no value assignment in your code.

0 new messages