blob: b43f7a80a81047d918efc630cf6c59cb66d143d8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
(defpackage zone
(:use :cl)
(:export :new-zone
:name
:update-zone
:get-commodity
:get-commodities))
(in-package :zone)
(defclass zone ()
((name :initarg :name
:reader name)
(commodities :initarg :commodities
:accessor commodities
:reader get-commodities)))
(defun new-zone (name commodities)
(make-instance 'zone
:name name
:commodities commodities))
(defmethod get-commodity ((z zone) commodity-name)
(find-if (lambda (c) (string= (commodities:name c)
commodity-name))
(commodities z)))
(defmethod update-zone ((z zone))
(loop for c in (commodities z)
do (setf (commodities:price c)
(* (commodities:price c)
(+ 0.5 (random 1.0))))))
|