Live data from Hacker News

A polyglot's guide to multiple dispatch – part 3

eli.thegreenplace.net

11–19 of 19 posts

Re: A polyglot's guide to multiple dispatch – part 3

#11

I mostly liked this article to show some of the basic features of CLOS, but was a little disappointed about the attitude toward the end. The attitude toward some of the more advanced features of CLOS like method combination reminds me of the attitude that some people have for functional programming. "Well, it's cool you can 'map' and 'reduce' a function across a list, but why not just use a for-loop?" I think most pe…

I wonder if anyone has a favorite example that uses method combinations, or auxiliary methods (:before, :after, :around), or something MOP related. Preferably one that is "in-the-wild" and not invented just to showcase the feature.

> Something MOP related

Postmodern[0] defines simple wrapper objects so that you can access databases rows as objects. The same goes for the Elephant persistent database[1]. Cells[2] define metaobjects for classes with dataflow dependencies where slots can be automatically updated in a reactive fashion.

:AROUND methods and the like are used quite often. In fact, the default way of defining a "constructor" function for your class is to specialize "initialize-instance" with an :after qualifier, so that you can fill slots that could not be initialized with the arguments to "make-instance" or the default initargs.

[0] http://marijnhaverbeke.nl/postmodern/

[1] https://common-lisp.net/project/elephant/

[2] https://common-lisp.net/project/cells/

Re: A polyglot's guide to multiple dispatch – part 3

#12
post #4

I mostly liked this article to show some of the basic features of CLOS, but was a little disappointed about the attitude toward the end. The attitude toward some of the more advanced features of CLOS like method combination reminds me of the attitude that some people have for functional programming. "Well, it's cool you can 'map' and 'reduce' a function across a list, but why not just use a for-loop?" I think most pe…

Indeed, where the article says: "these features are too advanced to be useful in 99% of the cases" I'm pretty sure when I wrote CLOS for a living (mind you, not recently) that I used :before, :around and :after rather more than that - they are a very natural and pretty simple extension to the basic method dispatch mechanism.

I mean they are if nothing else a good place to shove sanity-checking/design-by-contract code with out bloating (see: making harder to reason about) the actual method.

Re: A polyglot's guide to multiple dispatch – part 3

#13
post #4

I mostly liked this article to show some of the basic features of CLOS, but was a little disappointed about the attitude toward the end. The attitude toward some of the more advanced features of CLOS like method combination reminds me of the attitude that some people have for functional programming. "Well, it's cool you can 'map' and 'reduce' a function across a list, but why not just use a for-loop?" I think most pe…

Indeed, where the article says: "these features are too advanced to be useful in 99% of the cases" I'm pretty sure when I wrote CLOS for a living (mind you, not recently) that I used :before, :around and :after rather more than that - they are a very natural and pretty simple extension to the basic method dispatch mechanism.

Since ~2009 Perl 5 has had the Moo* ecosystem of modules (Moose, Moo, Mouse) to provide an object system that supports much of this. It was created as a backport of ideas for Perl 6's object system, which was heavily inspired by CLOS and the Smalltalk traits paper (always liberally steal the best ideas!).

That is, there's quite a lot of Perl 5 out there that makes extensive use of method modifiers[1] like before, after, around and friends.

1: http://search.cpan.org/dist/Moose/lib/Moose/Manual/MethodMod...

Re: A polyglot's guide to multiple dispatch – part 3

#15

I mostly liked this article to show some of the basic features of CLOS, but was a little disappointed about the attitude toward the end. The attitude toward some of the more advanced features of CLOS like method combination reminds me of the attitude that some people have for functional programming. "Well, it's cool you can 'map' and 'reduce' a function across a list, but why not just use a for-loop?" I think most pe…

I wonder if anyone has a favorite example that uses method combinations, or auxiliary methods (:before, :after, :around), or something MOP related. Preferably one that is "in-the-wild" and not invented just to showcase the feature.

At work we have a condition (think: exception) hierarchy that uses multiply inherited mixins. One might be validation-failure and introduce a slot telling you the invalid value. Another might be user-error that records the user that triggered the error. A third might carry an RPC error code for use if reported over RPC.

I used a generic function with list combination to collect from the mixins only the slots that should be reported over RPC. The user is not among them since it is always reported to the user that triggered the error.

Re: A polyglot's guide to multiple dispatch – part 3

#16

Earlier quoted context omitted.

I wonder if anyone has a favorite example that uses method combinations, or auxiliary methods (:before, :after, :around), or something MOP related. Preferably one that is "in-the-wild" and not invented just to showcase the feature.

At work we have a condition (think: exception) hierarchy that uses multiply inherited mixins. One might be validation-failure and introduce a slot telling you the invalid value. Another might be user-error that records the user that triggered the error. A third might carry an RPC error code for use if reported over RPC. I used a generic function with list combination to collect from the mixins only the slots that sho…

Seems pretty nifty, would love if you could share a gist [implementation] of the idea

Re: A polyglot's guide to multiple dispatch – part 3

#17

Earlier quoted context omitted.

At work we have a condition (think: exception) hierarchy that uses multiply inherited mixins. One might be validation-failure and introduce a slot telling you the invalid value. Another might be user-error that records the user that triggered the error. A third might carry an RPC error code for use if reported over RPC. I used a generic function with list combination to collect from the mixins only the slots that sho…

Seems pretty nifty, would love if you could share a gist [implementation] of the idea

Ah, it wasn't list, it was append. Though list would be fine if each mixin contributes no more than one item, I wanted mixins to be able to contribute more if necessary, so they always return lists which the combination appends to the result. It also allows them to decide to return nil and behave as though they were not called at all.

Here's a suitably abstracted implementation of the idea: https://gist.github.com/spacebat/dbad3b50684b3a516071abb3757...

Yes I am likening RPC programming to dealing with monsters in the darkness.

Re: A polyglot's guide to multiple dispatch – part 3

#18

I mostly liked this article to show some of the basic features of CLOS, but was a little disappointed about the attitude toward the end. The attitude toward some of the more advanced features of CLOS like method combination reminds me of the attitude that some people have for functional programming. "Well, it's cool you can 'map' and 'reduce' a function across a list, but why not just use a for-loop?" I think most pe…

I wonder if anyone has a favorite example that uses method combinations, or auxiliary methods (:before, :after, :around), or something MOP related. Preferably one that is "in-the-wild" and not invented just to showcase the feature.

Robert Smith gave a nice presentation involving using the MOP for defining abstract, final and singleton classes. Then he goes down a rabbit hole of user-defined JIT compilation:

https://dl.dropboxusercontent.com/u/734346/JIT-Compilation-o...

Re: A polyglot's guide to multiple dispatch – part 3

#19

Earlier quoted context omitted.

I wonder if anyone has a favorite example that uses method combinations, or auxiliary methods (:before, :after, :around), or something MOP related. Preferably one that is "in-the-wild" and not invented just to showcase the feature.

Robert Smith gave a nice presentation involving using the MOP for defining abstract, final and singleton classes. Then he goes down a rabbit hole of user-defined JIT compilation: https://dl.dropboxusercontent.com/u/734346/JIT-Compilation-o...

He mentions funcallable instances in the talk. Here's a toy example of such a creature: https://gist.github.com/spacebat/a2805737477ab330334edd1361b...
Post reply on HN