So my idea is to reduce the amount of calls to an object instance, when it is clearly the only one in scope.
Here’s a code example:
(defun read-plist (plist)
(let ((plist-reader (make-instance 'plist-reader))
(loop for (indicator value) in plist
do (read-indicator pr-instance indicator)
do (read-value pr-instance value))
plist-reader))
And here is what I want it to look like:
(defun read-plist (plist)
(let ((plist-reader (make-instance 'plist-reader))
(with-methods (read-indicator (rv read-value))
(loop for (indicator value) in plist
do (read-indicator indicator)
do (rv value)))
plist-reader))
I suppose it’s not really the best example since it makes the code look even more complicated. But I can imagine a case where it would shave off a good bit of complexity. Maybe I’m looking in a totally wrong direction, but my original idea is to reduce the use of names, when scope is clearly local. Would it simply be a better practice to have a small package of its own, where functions replace the need to bind methods to a specific object? I suppose there isn’t one true answer, but anyways.. What are your takes on the macro? 😀
I tried looking in the direction of defining the macro this way:
(defmacro with-methods (methods class-instance &rest code)
...)
But it seems I would need to look through all the rest code, figure find all the occurences of the given methods and modify them as lists. It raises a dilema of performance issues to me. Maybe there’s a classical approach to this that I have missed? From a standpoint of a Common Lisp beginner, I find documentation unsearchable and only readable after ChatGPT’s take on it tbh.
Alteration Dream is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.