4 ms·
> Now Elixir has an equivalent to multi, the Protocol. For what it's worth, Clojure also has a much closer fit to Elixir Protocols called... a Protocol. https
by tekacs 5y ago
> Now Elixir has an equivalent to multi, the Protocol.
For what it's worth, Clojure also has a much closer fit to Elixir Protocols called... a Protocol.
https://www.braveclojure.com/multimethods-records-protocols/#Protocols https://www.braveclojure.com/multimethods-records-protocols/...
They too can only dispatch on the type of the first argument, but are more structured (you can add multiple pieces of behavior at a time) and performant than multimethods where that's the behavior you're looking for.
- tekacs 5y agoI'll also leave these here, in case the conversation inevitably turns to pattern-matched function definition in Elixir. :) https://github.com/clojure/core.match https://github.com/clojure/core.match -- pattern matching as a library https://github.com/killme2008/defun https://github.com/killme2008/defun -- using core.match to implement Elixir/Erlang-like function definition https://github.com/noprompt/meander https://github.com/noprompt/meander -- advanced pattern matching, for some fun and flavor :) What's also fun is that core.match is implemented using a paper from INRIA on how to efficiently convert patterns into decision trees: https://github.com/clojure/core.match/wiki/Understanding-the-algorithm https://github.com/clojure/core.match/wiki/Understanding-the...
- jwhitlark 5y agoI've always loved that paper. Very readable, and gives good insights.
- SatvikBeri 5y agoIf videos are more your speed, David Nolen, the primary author of that library (and article) has a talk about it as well: https://www.youtube.com/watch?v=TVJa-V6U-XI https://www.youtube.com/watch?v=TVJa-V6U-XI
- didibus 5y agoElixir's Protocols actually were inspired by Clojure Protocols. Here's Jose Valim talking about it: > I’ve learned a lot also from Clojure because, at the time I was thinking about Elixir, Clojure was already around. I like to say it’s one of the top three influences in Elixir [...] > The main, the top three influences are Erlang, Ruby, and Clojure. [...] > I was like, no, but I’m going to call them protocols because there are a lot of similarities between Clojure and Elixir in terms of them being dynamic languages and in terms of the macro system. I was like, okay, I’m going to call them protocols because the closest thing we have today to what I want is Clojure And he goes on talking about more inspiration and similarities from Clojure like Agents, etc. Full exert is here: http://blog.cognitect.com/cognicast/120 http://blog.cognitect.com/cognicast/120