Make TRANSFORM return OBJ if it's already TO-TYPE

This commit is contained in:
John Lorentzson 2025-05-22 12:18:56 +02:00
parent 1307e31268
commit 7639263bed

View file

@ -57,12 +57,16 @@ that has been somehow created using OBJ as a starting point."
(let* ((from-type (case (type-of obj)
((bit number integer fixnum) 'integer)
(t (type-of obj))))
(path (transform-path from-type to-type)))
(if (listp path)
(path (if (typep obj to-type)
obj
(transform-path from-type to-type))))
(cond ((listp path)
(loop :for intermediate :in path
:do (setf obj (%direct-transform obj intermediate))
:finally (return (%direct-transform obj to-type)))
(%direct-transform obj to-type))))
:finally (return (%direct-transform obj to-type))))
((eql obj path)
obj)
(t (%direct-transform obj to-type)))))
(defmacro define-transformation ((var-name (from-type to-type)) &body body)
"Defines a transformation rule for objects going from FROM-TYPE to TO-TYPE.