The setf statement is actually a macro that should be able to verify the shape of a place already at compile time. He has special knowledge about aref , but knows nothing about your ret-aref .
The easiest way to make your function known to setf is by defining a suitable setf function companion for it. Example:
(defun (setf ret-aref) (new-value array index) (setf (aref array index) new-value))
Now (setf (ret-aref arr 0) 'bar) should work.
This simple example hides the fact that setf extension is actually a pretty hairy topic. You can find gory details at CLHS .
source share