[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Generating a list of enumerated symbols

William James

3/28/2015 11:29:00 PM

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

taruss

3/30/2015 4:57:00 PM

0

On Saturday, March 28, 2015 at 4:29:50 PM UTC-7, WJ wrote:
> 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.

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.