Skip to content

Commit

Permalink
add arg-position to GENERALIZER-OF-USING-CLASS
Browse files Browse the repository at this point in the history
Suggested-by: Christophe Rhodes in #3.
  • Loading branch information
scymtym committed Jun 14, 2014
1 parent eff2afd commit ecab7a3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/accept-specializer/accept-specializer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@
(,@(rest around) (make-method ,form))))
(wrap form)))))

(defmethod generalizer-of-using-class ((gf accept-generic-function) (s string))
(defmethod generalizer-of-using-class ((gf accept-generic-function)
(s string) arg-position)
(make-instance 'accept-generalizer
:header s
:next (call-next-method)))
Expand Down
3 changes: 2 additions & 1 deletion src/accept-specializer/hunchentoot.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

(cl:in-package #:accept-specializer)

(defmethod generalizer-of-using-class ((gf accept-generic-function) (arg tbnl:request))
(defmethod generalizer-of-using-class ((gf accept-generic-function)
(arg tbnl:request) arg-position)
(make-instance 'accept-generalizer
:header (tbnl:header-in :accept arg)
:next (call-next-method)))
Expand Down
2 changes: 1 addition & 1 deletion src/cons-specializer/cons-specializer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;;; FIXME: make a proper generalizer
(defmethod generalizer-equal-hash-key ((gf cons-generic-function) (g symbol))
g)
(defmethod generalizer-of-using-class ((gf cons-generic-function) arg)
(defmethod generalizer-of-using-class ((gf cons-generic-function) arg arg-position)
(typecase arg
((cons symbol) (car arg))
(t (call-next-method))))
Expand Down
8 changes: 5 additions & 3 deletions src/protocol.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
TODO extend"))

;; new, not in closette
(defgeneric generalizer-of-using-class (generic-function object)
(defgeneric generalizer-of-using-class (generic-function object arg-position)
(:documentation
"Return a generalizer object representing OBJECT (an argument with
which GENERIC-FUNCTION is being called).
which GENERIC-FUNCTION is being called). ARG-POSITION is the
position of object in the lambda-list of GENERIC-FUNCTION.
This is called done for each required argument."))
This is called once for each pair of required argument OBJECT and
its position in the lambda-list ARG-POSITION."))

(defgeneric compute-applicable-methods-using-generalizers (generic-function generalizers)
(:documentation
Expand Down
10 changes: 6 additions & 4 deletions src/specializable.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,13 @@

(defmethod generalizers-of-using-class ((generic-function specializable-generic-function)
args num-required)
(map-into (make-list num-required)
(lambda (arg) (generalizer-of-using-class generic-function arg))
args))
(loop ; TODO check whether this is as efficient as (map-into (make-list num-required) ...)
:for i :of-type fixnum :from 0 :below num-required
:for arg in args
:collect (generalizer-of-using-class generic-function arg i)))

(defmethod generalizer-of-using-class ((generic-function specializable-generic-function) object)
(defmethod generalizer-of-using-class ((generic-function specializable-generic-function)
object arg-position)
(class-of object))

(defmethod specializer-accepts-generalizer-p
Expand Down

0 comments on commit ecab7a3

Please sign in to comment.