Created
November 1, 2010 04:35
-
-
Save kurohuku/657611 to your computer and use it in GitHub Desktop.
ref , size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun defmethods-args-expander (args specifiers) | |
(when (< (length args) (length specifiers)) | |
(error "Too many specifiers")) | |
(labels | |
((inner (ar sr acc) | |
(if (null ar) | |
(nreverse acc) | |
(inner (cdr ar) | |
(cdr sr) | |
(cons | |
(if (null sr) | |
(car ar) | |
(list (car ar) (car sr))) | |
acc))))) | |
(inner args specifiers nil))) | |
(defun defmethods-clause-expander (name args clause) | |
(destructuring-bind (specifiers &rest definition) | |
clause | |
(unless (listp specifiers) | |
(setf specifiers (list specifiers))) | |
`(defmethod ,name | |
,(defmethods-args-expander args specifiers) | |
,@definition))) | |
(defmacro defmethods (name (&rest args) &body clauses) | |
(when (null args) | |
(error "There is no argument")) | |
`(progn | |
,@(mapcar | |
#'(lambda (clause) | |
(defmethods-clause-expander name args clause)) | |
clauses))) | |
(defgeneric size (object)) | |
(defmethods size (object) | |
(list (length object)) | |
(integer (integer-length object)) | |
(file-stream (file-length object))) | |
(defgeneric ref (object place)) | |
(defmethods ref (object place) | |
((sequence integer) (elt object place)) | |
((simple-vector integer) (svref object place)) | |
((array integer) (aref object place)) | |
((array list) (apply #'aref object place)) | |
((list integer) (nth place object)) | |
((list T) (assoc place object))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment