What I would like to write is this:
(defun generate-cities (city-number)
(let ((these-cities (make-instance 'cities)))
(with-accessors (x y order) these-cities
(setf x (make-array city-number :element-type 'single-float)
y (make-array city-number :element-type 'single-float)
order (make-array city-number :element-type 'fixnum))
(loop for i from 0 to (1- city-number) do
(setf (aref x i) (random-float)
(aref y i) (random-float)
(aref order i) i)))
these-cities))
But this gives me an error: x not of type CONS (in LispWorks)
Instead I have to write something like this:
(defun generate-cities (city-number)
(let ((cities (make-instance 'cities)))
(let (x-temp y-temp order-temp)
(setf x-temp (make-array city-number :element-type 'single-float)
y-temp (make-array city-number :element-type 'single-float)
order-temp (make-array city-number :element-type 'fixnum))
(loop for i from 0 to (1- city-number) do
(setf (aref x-temp i) (random-float)
(aref y-temp i) (random-float)
(aref order-temp i) i))
(setf (x cities) x-temp (y cities) y-temp (order cities) order-temp))
cities))
Why is the first an error?
What is the point of with-accessors if it is not setf'able?
--
Using M2, Opera's revolutionary e-mail client:
http://www.opera.com/m2/(defun generate-cities (city-number)
On Wed, 19 Jan 2005 20:31:04 +0100, John Thingstad
<··············@chello.no> wrote:
>
> Why is the first an error?
> What is the point of with-accessors if it is not setf'able?
>
Forget it!
Forgot about the second argument.
shold have been:
(with accessors ((x x) (y y) (order order)) these-cities
(Though it looks like a severe case of stuttering.)
I was thinking of with-slots.
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
On 21 Jan 2005 13:24:22 -0800, Thomas A. Russ <···@sevak.isi.edu> wrote:
>
> What is the definition of class CITIES ?
>
(defclass cities ()
((city-number :accessor city-number)
(x :accessor x)
(y :accessor y)
(index-order :accessor index-order)))
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/