What I really miss in CL from time to time, is a true dynamic function binding or possibility to override non-generic function with generic one.
This approach:
1 2 3 4 5 6 |
(defparameter *original-schar* #'schar)
(defmethod generic-schar ((o string) i)
(funcall *original-schar* o i))
(without-package-locks
(defun schar (s i)
(funcall #'generic-schar s i))) |
definitely sucks and will not work for all functions (for example, it will halt for LENGTH)
I think that duck typing rocks for some cases. But it is hard (well, mostly impossible) to use it for built-in CL types (to let arbitrary data type quack like, say, vector).
Or is it something wrong with me and I should not want to use this practice for CL?
Deep in thought.





You might want to try
(shadow ‘schar) (defgeneric schar (o i) (cl:schar o i))
sross,
Thank you! Definitely, I forgot about shadowing.
Nothing wrong with this practice, no, but I’m curious what you want it for. I think this sort of thing is partly a matter of what’s easiest for you to conceptualize, which is an individual thing. I don’t think I’ve ever wanted to do this, except for the part about making my own vector types.
Dan,
Well, in this particular case I needed to to “teach” some library work with types that weren’t supported.