4 ms·
> (defgeneric xplusone (x) (1+ x)) > The sbcl compiler (called python) even creates the typed methods by itself, so mostly the defgeneric line is enough. I
by xrange 10y ago
> (defgeneric xplusone (x) (1+ x))
> The sbcl compiler (called python) even creates the typed methods by itself, so mostly the defgeneric line is enough.
Is this some new SBCL extension you are talking about? That `defgeneric` line is an error in CLOS.
- nuntius 10y agoVery much a part of the standard. i.e. not specific to SBCL. Think of defgeneric as the function signature and defmethod as the template specialization. Not sure why you say this is an error in CLOS. Looks fine to me. That said, most implementations try to auto-infer the generic function metaobject when you use defmethod without defgeneric. SBCL raises a warning. Good reads on the topic: http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html http://www.gigamonkeys.com/book/object-reorientation-generic... https://mitpress.mit.edu/books/art-metaobject-protocol https://mitpress.mit.edu/books/art-metaobject-protocol http://mop.lisp.se/ http://mop.lisp.se/
- juki 10y agoThe DEFGENERIC line is wrong. It can't have a body like that. It should be something like (defgeneric xplusone (x) (:method (x) (+ 1 x))) Also, generic functions are slower than regular functions (due to dynamic dispatch), so using them for type optimization would be rather counterproductive.
- rurban 10y agoYes, thanks. I only wanted to point out similarities to abstract classes, generic slow methods.