Introduction Didier Verna google+ didier.verna @didierverna lrde/~didier didier@lrde.epita.fr EPITA / LRDE in/didierverna Issues Method Combinators Conclusion Perfs Alt. MCs CGFs Combinators SBCL e ELS 2018 E
Introduction Issues Method Combinators / ELS 2018 – Didier Verna Unclear or contradictory protocols Considered not mature enough Increased SOC: methods / dispatch Homogeneous behavioral refmection Increased SOC: polymorphism / inheritance Introduction Conclusion Perfs Alt. MCs CGFs Combinators SBCL 2/27 ◮ CLOS improvements over mainstream object systems ◮ Multiple dispatch ◮ MOP ◮ Method combinations ◮ Standardization drawbacks ◮ Method combinations underspecifjed ◮ MOP only a later addition
Introduction Method Combinations Issues Method Combinators / ELS 2018 – Didier Verna Performance Alternative Combinators Combined Generic Functions Method Combinators The Case of SBCL Plan Issues Conclusion Perfs Alt. MCs CGFs Combinators SBCL 3/27
Introduction Method Combinations Issues Method Combinators / ELS 2018 – Didier Verna Performance Alternative Combinators Combined Generic Functions Method Combinators The Case of SBCL Plan Issues Conclusion Perfs Alt. MCs CGFs Combinators SBCL 4/27
Introduction (defgeneric details (human) Method Combinators / ELS 2018 – Didier Verna No good reason Inconsistent Combination change impractical (:method append ((employee employee)) ...)) Issues (:method-combination append :most-specific-last) (:method append ((human human)) ...) Short combination example Orthogonality Conclusion Perfs Alt. MCs CGFs Combinators SBCL 5/27 ◮ Problems ◮ Method qualifjcation required ◮ Except for the option ◮ No :before or :after methods ◮ Workaround: long method combinations
Introduction Issues Method Combinators / ELS 2018 – Didier Verna Mix of defjne / call-time parametrization At least one implementation-specifjc (sub)class Abstract <unspecifjed> method-combination System classes Structure Conclusion Perfs Alt. MCs CGFs Combinators SBCL 6/27 ◮ Portable specialization impossible ◮ Unclear nature (classes vs. instances)
Introduction Protocols Method Combinators / ELS 2018 – Didier Verna generic function” find-method-combination gf name options Issues Lookup (MOP) Conclusion Perfs Alt. MCs CGFs Combinators SBCL 7/27 ◮ “called to determine the combination object used by a ◮ What are name and options for? ◮ Error behavior? ◮ There already is generic-function-method-combination
Introduction Issues SBCL Combinators CGFs Alt. MCs Perfs Conclusion Protocols (cont.) Generic function invocation protocol (MOP) compute-effective-method gf combination methods Contrary to applicable methods Method Combinators / ELS 2018 – Didier Verna 8/27 ◮ What is combination for? ◮ Caching policy unspecifjed
Introduction Method Combinations Issues Method Combinators / ELS 2018 – Didier Verna Performance Alternative Combinators Combined Generic Functions Method Combinators The Case of SBCL Plan Issues Conclusion Perfs Alt. MCs CGFs Combinators SBCL 9/27
Introduction Issues Method Combinators / ELS 2018 – Didier Verna args-lambda-list function long-method-combination identity-with-one-argument operator short-method-combination options type-name standard-method-combination Method combination classes hierarchy Classes Conclusion Perfs Alt. MCs CGFs Combinators SBCL 10/27 ◮ options : use-time ( :method-combination options) ◮ Below: defjne-time
Introduction (define-method-combination name option*) Method Combinators / ELS 2018 – Didier Verna short combination object gf (eql name) options) / / Issues (find-method-combination / Creation Short Method Combinations Conclusion Perfs Alt. MCs CGFs Combinators SBCL 11/27 ◮ No global namespace ◮ One method combination object per generic function ◮ Redefjnitions don’t afgect existing generic functions ◮ find-method-combination � = the expected or the specifjed
Introduction Issues Method Combinators / ELS 2018 – Didier Verna args-lambda-list function long-method-combination *long-method-combination-functions* Long method combination functions Long Method Combinations Conclusion Perfs Alt. MCs CGFs Combinators SBCL 12/27 ◮ Similar behavior, one additional oddity ◮ Local method combination objects ◮ Global method combination functions
Introduction `(call-method , method )) Method Combinators / ELS 2018 – Didier Verna NUMBER FIXNUM CL-USER> (test 1) REPL (:method ((i fixnum )) (print 'fixnum))) (:method ((i number )) (print 'number)) (defgeneric test (i) (:method-combination my-progn) primary))) `( progn ,@(mapcar ( lambda ( method ) Issues ((primary () :order :most-specific-first :required t)) (define-method-combination my-progn () Code Long Method Combinations (cont.) Conclusion Perfs Alt. MCs CGFs Combinators SBCL 13/27
Introduction `( progn ,@(mapcar ( lambda ( method ) Method Combinators / ELS 2018 – Didier Verna NUMBER FIXNUM CL-USER> (test 1) REPL . primary))) `(call-method , method )) ((primary () :order :most-specific-last :required t)) Issues (define-method-combination my-progn () Code Long Method Combinations (cont.) Conclusion Perfs Alt. MCs CGFs Combinators SBCL 13/27
Introduction . Method Combinators / ELS 2018 – Didier Verna NUMBER FLOAT FIXNUM NUMBER CL-USER> (test 1) CL-USER> (test 1.5) REPL (defmethod test ((i float)) (print 'float)) Issues Code Long Method Combinations (cont.) Conclusion Perfs Alt. MCs CGFs Combinators SBCL 13/27
Introduction Method Combinations Issues Method Combinators / ELS 2018 – Didier Verna Performance Alternative Combinators Combined Generic Functions Method Combinators The Case of SBCL Plan Issues Conclusion Perfs Alt. MCs CGFs Combinators SBCL 14/27
Introduction Issues Method Combinators / ELS 2018 – Didier Verna long-method-combinator short-method-combinator long-method-combination short-method-combination clients method-combinator-mixin Classes Overview Conclusion Perfs Alt. MCs CGFs Combinators SBCL 15/27 ◮ Stored in a global hash table ◮ [setf] find-method-combinator
Introduction Issues SBCL Combinators CGFs Alt. MCs Perfs Conclusion Protocols In 3 layers define-[short|long]-method-combinator ensure-[short|long]-method-combinator ensure-[short|long]-method-combinator-using-class Method Combinators / ELS 2018 – Didier Verna 16/27
Introduction Issues Method Combinators / ELS 2018 – Didier Verna (setf find-method-combinator) store it (change-class) make it combinator (find-method-combination) retrieve it defjne a regular combination In 4 steps Implementation (layer 3) Conclusion Perfs Alt. MCs CGFs Combinators SBCL 17/27 ◮ Note: regular combination injection
Introduction Method Combinations Issues Method Combinators / ELS 2018 – Didier Verna Performance Alternative Combinators Combined Generic Functions Method Combinators The Case of SBCL Plan Issues Conclusion Perfs Alt. MCs CGFs Combinators SBCL 18/27
Introduction funcallable-standard-class Method Combinators / ELS 2018 – Didier Verna ...) (:method-combinator mc) (defcombined cgf (args...) Wrappers «instanceof» functions combined-generic-function standard-generic-function Issues Classes Overview Conclusion Perfs Alt. MCs CGFs Combinators SBCL 19/27
Introduction Issues Method Combinators / ELS 2018 – Didier Verna (change-method-combinator cgf method-combinator) (method-combinator cfg) #|or mismatch error|# ) (defmethod find-method-combination (cgf ...) (find-method-combinator ...)) (defmethod find-method-combination (cgf-class-prototype ...) 20/27 Method Combinator Management Conclusion Perfs Alt. MCs CGFs Combinators SBCL ◮ Initialization ◮ Sanitation ◮ Updating
Introduction Issues Method Combinators / ELS 2018 – Didier Verna update-combined-generic-function-for-redefined-method-combinator make-clients-obsolete New protocol (u-i-f-d-c mc ...) (reinitialize-instance mc ...) ([re]initialize-instance cgf ...) cgf cgf cgf clients method-combinator-mixin Client Maintenance Conclusion Perfs Alt. MCs CGFs Combinators SBCL 21/27 ◮ Client registration: ◮ Client updating:
Introduction Method Combinations Issues Method Combinators / ELS 2018 – Didier Verna Performance Alternative Combinators Combined Generic Functions Method Combinators The Case of SBCL Plan Issues Conclusion Perfs Alt. MCs CGFs Combinators SBCL 22/27
Introduction Issues Method Combinators / ELS 2018 – Didier Verna #!combinator(func arg1 arg2 ...) (call/cb combinator func arg1 arg2 ...) #'func arg1 arg2 ...) (call-with-combinator (find-method-combinator 'combinator) Protocols 23/27 Overview Conclusion Perfs Alt. MCs CGFs Combinators SBCL ◮ Idea: generic functions / combinators complete decoupling ◮ Use: � = logical method combinations, selected methods etc. ◮ Note: already possible, but extremely costly ◮ 2 calls to reinitialize-instance
Recommend
More recommend