TXR Lisp: (defstruct product nil sku price) (defstruct event nil) (defstruct add-to-basket event product quantity) (defstruct line nil product-sku quantity line-total) (defstruct basket nil lines total (:postinit (me) (set me.total [reduce-left + me.lines 0 (usl line-total)]))) (defvarl empty-basket (new basket)) (defun build-line (product quantity) (new line product-sku product.sku quantity quantity line-total (* qu…
(defmeth basket add-to (me product quantity)
(labels ((insert (lines)
(tree-case lines
((line . rest) (if (equal line.product-sku product.sku)
(cons (build-line product
(+ line.quantity quantity))
rest)
(cons line (insert rest))))
(() (list (build-line product quantity))))))
(new basket lines (insert me.lines))))