News for hackers. Stuff that matters.
Re:Modern C++ and Lisp Programming Style by rurban on Wednesday March 22, 2017 @03:11PM (#13933785)
I cannot say much about the C++ code, but the lisp examples are very bad style. One does not write like this.

One writes ordinary generic functions, and then optimized typed methods in lisp like this:

    (defgeneric xplusone (x) (1+ x))
    (defmethod xplusone ((x integer)) (1+ x))
    (defmethod xplusone ((x double-float)) (1+ x))
The sbcl compiler (called python) even creates the typed methods by itself, so mostly the defgeneric line is enough. The type hints for args and return types are purely optional, as the compiler figures it out by itself.

He is right that algorithms, methods, trump data structures, objects. You always write methods with specializations on objects. Not the other way round, classes with specific methods.

Re:Modern C++ and Lisp Programming Style by xrange on Wednesday March 22, 2017 @03:38PM (#13934058)
> (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.

Re:Modern C++ and Lisp Programming Style by nuntius on Wednesday March 22, 2017 @09:46PM (#13936818)
Very 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...

https://mitpress.mit.edu/books/art-metaobject-protocol

http://mop.lisp.se/

Re:Modern C++ and Lisp Programming Style by juki on Thursday March 23, 2017 @01:10AM (#13937536)
The 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.
Re:Modern C++ and Lisp Programming Style by rurban on Thursday March 23, 2017 @07:48AM (#13938934)
Yes, thanks. I only wanted to point out similarities to abstract classes, generic slow methods.