summaryrefslogtreecommitdiffstats
path: root/src/commodities.lisp
blob: 6f8c65d38dd10dd79bdf3a19afca77b017074d5a (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
(defpackage :commodities
  (:use :cl)
  (:export :new-commodity
		   :name
		   :price
		   :commodity-eq))

(in-package :commodities)

(defclass commodity ()
  ((name :initarg :name
		 :reader name)
   (price :initarg :price
		  :accessor price)))

(defun new-commodity (name price)
  (when (> price 0)
	(make-instance 'commodity
				   :name name
				   :price price)))

(defmethod print-object ((object commodity) stream)
  (print-unreadable-object (object stream :type t)
	(with-slots (name price) object
	  (format stream "~a worth ~a" name price))))

(defmethod commodity-eq ((c1 commodity) (c2 commodity))
  (and (equal (name c1) (name c2))
	   (= (price c1) (price c2))))