* Amendments

- Initial test modified to be similar to Clojure version
- update-quality modified to read from make-item directly. Helper methods removed
This commit is contained in:
mgd authored and Peter Kofler committed 2024-10-18 15:32:03 +02:00
1 parent 3615cfb8ab
commit 91ebc85a70
3 files changed
+15 -26

No files matched your search

+8 -23
View File
@@ -2,37 +2,22 @@
"Create an item with NAME, SELL-IN, and QUALITY."
(list :name name :sell-in sell-in :quality quality))
(defun item-name (item)
"Return the name of ITEM."
(plist-get item :name))
(defun item-sell-in (item)
"Return the sell-in value of ITEM."
(plist-get item :sell-in))
(defun item-quality (item)
"Return the quality of ITEM."
(plist-get item :quality))
(defun update-quality (item)
"Update the quality of the ITEM according to the Gilded Rose rules."
(let ((quality (item-quality item))
(sell-in (item-sell-in item)))
(let* ((quality (plist-get item :quality))
(sell-in (plist-get item :sell-in))
(name (plist-get item :name)))
(cond
;; Aged Brie
((string= (item-name item) "Aged Brie")
((string= name "Aged Brie")
(setf (nth 2 item) (min 50 (1+ quality))))
;; Backstage passes
((string= (item-name item) "Backstage passes")
((string= name "Backstage passes")
(cond
((> sell-in 10) (setf (nth 2 item) quality))
((and (<= sell-in 10) (> sell-in 5)) (setf (nth 2 item) (min 50 (+ quality 2))))
((and (<= sell-in 5) (> sell-in 0)) (setf (nth 2 item) (min 50 (+ quality 3))))
(t (setf (nth 2 item) 0))))
;; Sulfuras
((string= (item-name item) "Sulfuras")
((string= name "Sulfuras")
(setf (nth 2 item) quality))
(t
(setf (nth 2 item) (max 0 (1- quality)))))))
(provide 'gilded-rose)