Well, it expresses the idea...
; replace _only_ the lowest valued structure in the group object
(defstruct appliance dryer)
(defclass store () ; holds 'foos
((alpha :accessor ALPHA :initarg :alpha)
(beta :accessor BETA :initarg :beta)
(gamma :accessor GAMMA :initarg :gamma)))
(let* ( (mayt (make-appliance :dryer 5))
(frid (make-appliance :dryer 3))
(king (make-appliance :dryer 7))
(newt (make-appliance :dryer 11)) ; the value to be inserted
(ohio (make-instance 'store :alpha mayt :beta frid :gamma king)) )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; listing slots just isn't it
(let* ( (choices (list (list "ALPHA" (appliance-dryer (ALPHA ohio))) ; an accessor for find-symbol
(list "BETA" (appliance-dryer (BETA ohio)))
(list "GAMMA" (appliance-dryer (GAMMA ohio)))))
(theone (car choices)) ) ; set to this in the first comparison anyway
(print-store ohio)
(format t "new-member? ~A~%" newt)
(dolist (choice choices) ; walk the list to find the smallest
(when (< (cadr choice) (cadr theone))
(setf theone choice)))
(format t "slot to consider replacing ~A~%" theone)
(when (> (appliance-dryer newt) (cadr theone))
(setf (slot-value ohio (find-symbol (string (car theone)))) (make-appliance :dryer (appliance-dryer newt))))
; I've forgotten why that line ended up that way. It was probably the first thing that worked.
(print-store ohio)
))
(defun print-store (t-obj) ; is there a CLOS created hook somewhere?
(format t "STORE: alpha ~A beta ~A gamma ~A ~%" (ALPHA t-obj) (BETA t-obj) (GAMMA t-obj)))
But there is clearly a better way out there...
--
Being a Slime user means living in a house inhabited by a family of
crazed carpenters. When you wake up, the house is different. Maybe
there is a new turret, or some walls have moved, or perhaps someone
has removed the floor under your bed.