TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Elixir protocols vs. Clojure multimethods

160 点作者 sandbags将近 4 年前

9 条评论

tekacs将近 4 年前
&gt; Now Elixir has an equivalent to multi, the Protocol.<p>For what it&#x27;s worth, Clojure also has a much closer fit to Elixir Protocols called... a Protocol.<p><a href="https:&#x2F;&#x2F;www.braveclojure.com&#x2F;multimethods-records-protocols&#x2F;#Protocols" rel="nofollow">https:&#x2F;&#x2F;www.braveclojure.com&#x2F;multimethods-records-protocols&#x2F;...</a><p>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&#x27;s the behavior you&#x27;re looking for.
评论 #27865531 未加载
评论 #27869108 未加载
kopos将近 4 年前
Having worked with both to create the same system (building a game server) I&#x27;ve found Clojure actually sits better with the functional thinking style (1 data structure, 100 functions).<p>While Phoenix was the killer app for Elixir, and Elixir has far superior readability (using the Ruby syntax); there were couple of things that were off-putting and I struggled with them.<p>1. everything is inside a module was an unnecessary distraction<p>2. And then the separation between anonymous and named functions simply were unnecessary<p>3. And that I would have to declare the data &#x2F; record inside a module (??)<p>Elixir felt like a functional language un-necessarily trying to look like a class based language.<p>I sometimes feel that had Elixir had only supported functions outside of modules... oh that freedom.<p>But some of the thought that went into Flow, Channels (which has become the de riguere now), mix (developer ergonomics ftw), those micro-second latency responses, distillery are still too classy and amazing.
评论 #27867198 未加载
评论 #27867225 未加载
评论 #27868052 未加载
评论 #27867362 未加载
评论 #27868655 未加载
Aboh33将近 4 年前
I recently found there was a clojure implementation for .NET and also one for the BEAM Virtual Machine. Has anyone used the latter? Regards<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;clojure&#x2F;clojure-clr" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;clojure&#x2F;clojure-clr</a> [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;clojerl&#x2F;clojerl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;clojerl&#x2F;clojerl</a>
评论 #27865705 未加载
评论 #27869161 未加载
评论 #27867852 未加载
dnautics将近 4 年前
You can, you can match against the module in the struct of the second parameter, concatenate the two modules, and manually dispatch against the concatenated module. I don&#x27;t really recommend this (it is not performant and feels like a code smell), but it is possible
评论 #27865597 未加载
评论 #27865770 未加载
ollysb将近 4 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;OvermindDL1&#x2F;protocol_ex" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;OvermindDL1&#x2F;protocol_ex</a> gives you protocols with full pattern matching.
评论 #27868729 未加载
tobyhinloopen将近 4 年前
Using dashes in function names? Blasphemy
评论 #27867857 未加载
评论 #27868688 未加载
rainygold将近 4 年前
Feels like Elixir has stolen much of Clojure&#x27;s appeal and &#x27;thunder&#x27; as the niche pragmatic functional language.
评论 #27866121 未加载
评论 #27868719 未加载
评论 #27866710 未加载
评论 #27867657 未加载
评论 #27867363 未加载
评论 #27870385 未加载
nsonha将近 4 年前
protocols are still just single dispatch like interfaces and virtuals in other languages. This person uses a title that makes it seem like Elixir has multiple dispatch, only to conclude at the end that protocols are nothing like multimethods.
dmitriid将近 4 年前
It&#x27;s one of those &quot;rarely used in practice but insanely frustrating when you write a library or some generalized code&quot;.<p>However, I&#x27;d rather Clojure got proper pattern-matching than Elixir multimethods. I find pattern matching a much more powerful, flexible and useful tool.
评论 #27865535 未加载