knowledge-database (beta)

Current group: comp.lang.lisp

with-accessors question

with-accessors question  
John Thingstad
 Re: with-accessors question  
Thomas A. Russ
 Re: with-accessors question  
John Thingstad
 Re: with-accessors question  
John Thingstad
From:John Thingstad
Subject:with-accessors question
Date:Wed, 19 Jan 2005 20:31:04 +0100
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)
From:Thomas A. Russ
Subject:Re: with-accessors question
Date:21 Jan 2005 13:24:22 -0800

What is the definition of class CITIES ?

--
Thomas A. Russ, USC/Information Sciences Institute
From:John Thingstad
Subject:Re: with-accessors question
Date:Sat, 22 Jan 2005 00:22:02 +0100
On 21 Jan 2005 13:24:22 -0800, Thomas A. Russ 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/
From:John Thingstad
Subject:Re: with-accessors question
Date:Wed, 19 Jan 2005 20:41:12 +0100
On Wed, 19 Jan 2005 20:31:04 +0100, John Thingstad
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/
   

Copyright © 2006 knowledge-database   -   All rights reserved