WJ
unread,Mar 28, 2015, 7:29:50 PM3/28/15You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.