[Openmcl-devel] Applying sequence functions to a new type

bryan o'connor bryan-openmcl at lunch.org
Tue Mar 1 13:41:42 PST 2005


> Alternatively, can I somehow define a user sequence function which is 
> a GENERIC-FUNCTION and then call the original function when the input 
> is not my user data structure?

if i understand what you mean, you can do something like this:

(defclass vec2 ()
   ((a :accessor a
       :initarg :a)
    (b :accessor b
       :initarg :b)))

(defmethod my-elt (o i)
   (elt o i))

(defmethod my-elt ((o vec2) i)
   (cond ((= 0 i) (slot-value o 'a))
         ((= 1 i) (slot-value o 'b))
         (t 'error)))

? (let ((v  #(0 1 2))
         (v2 (make-instance 'vec2 :a 'a :b 'b)))
     (values (my-elt v 0)
             (my-elt v2 0)))
0
A




More information about the Openmcl-devel mailing list