Generic functions for non-generic functions 4

Posted by yrashk

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.

Comments

Leave a response

  1. srossAugust 30, 2006 @ 08:50 PM

    You might want to try

    (shadow ‘schar) (defgeneric schar (o i) (cl:schar o i))

  2. Yurii RashkovskiiAugust 31, 2006 @ 01:43 AM

    sross,

    Thank you! Definitely, I forgot about shadowing.

  3. Dan KnappAugust 31, 2006 @ 04:56 AM

    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.

  4. Yurii RashkovskiiAugust 31, 2006 @ 06:06 AM

    Dan,

    Well, in this particular case I needed to to “teach” some library work with types that weren’t supported.

Comment