Hello guys,
can I ask you for help regarding my problem?
I would like to create shop with cars. Then I will create two cars and I will put these cars to slot "cars" to my shop. I want to create method which will take cost of all cars from my shop and give back some number. could you advice pls ?
first car:
second car:
any idea pls?
can I ask you for help regarding my problem?
I would like to create shop with cars. Then I will create two cars and I will put these cars to slot "cars" to my shop. I want to create method which will take cost of all cars from my shop and give back some number. could you advice pls ?
(defclass autoshop () ((cars :initform nil :accessor cars)
(name :initarg :name :reader name) ))
(defclass automobile ()
((car_name :initform nil :accessor car_name)
(cost :initform nil :accessor cost)))
>(setf greencar (make-instance 'autoshop))
>(setf (slot-value greencar 'name) 'Green_car_shop) .....my shop will be called 'Green_car_shop'first car:
>(setf audi (make-instance 'automobile))
>(setf (slot-value audi 'car_name) 'AudiA3)
>(setf (slot-value audi 'cost) 10000)
result:
#<AUTOMOBILE 2183BD67> is an AUTOMOBILE
CAR_NAME AUDIA3
COST 10000
second car:
>(setf bmw (make-instance 'automobile))
>(setf (slot-value bmw 'cost) 12000)
>(setf (slot-value bmw 'car_name) 'BmwM3)
result:
#<AUTOMOBILE 21854D3B> is an AUTOMOBILE
CAR_NAME BMWM3
COST 12000
Then I will put these cars to my shop:
>(push bmw (slot-value greencar 'cars))
>(push audi (slot-value greencar 'cars))
results:
#<AUTOSHOP 2180F753> is an AUTOSHOP
CARS (#<AUTOMOBILE 2183BD67> #<AUTOMOBILE 21854D3B>)
NAME GREEN_CAR_SHOP
How to continue pls? In case of these 2 cars, it should return 22000. when I will put there third car with cost 11000, cost will be 33000.
(defmethod cost_of_all_cars ((autoshop autoshop))
????????????
)
For example:
(defmethod cost_of_all_cars ((autoshop autoshop))
(list (cars autoshop)) )
CL-USER 33 > (cost_of_all_cars greencar)
((#<AUTOMOBILE 2183BD67> #<AUTOMOBILE 21854D3B>))
but how to get in to the slots called cost and calculate costs of all cars? any idea pls?