4 ms·
This wouldn't really be Hacker News unless an arrogant Lisp devotee shows up and claims that Lisp does everything better, so I'll now try to be that arrogant Li
by lkrubner 8y ago
This wouldn't really be Hacker News unless an arrogant Lisp devotee shows up and claims that Lisp does everything better, so I'll now try to be that arrogant Lisp devotee.
Sean Johnson has given a fantastic talk about pattern matching in Clojure:
https://www.youtube.com/watch?v=n7aE6k8o_BU https://www.youtube.com/watch?v=n7aE6k8o_BU
He offers some interesting comparisons between Clojure and Erlang.
Going even further, I recently discovered Dynamatch:
https://github.com/metasoarous/dynamatch https://github.com/metasoarous/dynamatch
"Dynamatch addresses these challenges by enforcing a certain structure in our ordering of match clauses such that many of the incidental complexities of order dependence in a dynamically extensible pattern matching system become more manageable."
Sometimes it seems like Erlang or Haskell has the last word in Pattern Matching, but I'm not aware of anything like Dynamatch in those languages.
- arethuza 8y agoWhat about method dispatch in CLOS, pretty sure that counts as "does everything better" - at least when it comes to mapping tuples of values to methods.
- kazinator 8y agoMethod dispatch is arguably a form of pattern matching: pattern matching on the type signature of the argument tuple. (With eql specializers, on the object/numeric identities of the arguments, not only types).
- Jtsummers 8y agoAnd with some CLOS extensions, it can also be extended to other filters besides just eql specializers (this is also in Clojure's implementation of multiple dispatch).
- Jtsummers 8y agohttp://www.p-cos.net/documents/filtered-dispatch.pdf http://www.p-cos.net/documents/filtered-dispatch.pdf The link I meant to include before.
- bastawhiz 8y agoNo thread on HN would be complete without the JavaScript programmer jumping in to "well actually" your response, so I formally nominate myself to fill that role. ECMAScript is getting pattern matching! It's currently a stage 1 proposal with backing from Microsoft, npm, and Facebook. https://github.com/tc39/proposal-pattern-matching https://github.com/tc39/proposal-pattern-matching
- Scarbutt 8y agoI was researching clojure vs nodejs for a webapp, but found that the benefits clojure provides are very small and not enough compared to the benefits you get with JS the ecosystem. And Javascript 2019 is actually nice.
- jwr 8y agoThe usual problem with such comparisons is that in order to understand the benefits of Clojure/ClojureScript, you have to use those tools to write a reasonably large system. Otherwise the comparisons are superficial. The other problem is that most comparisons are apples-to-oranges. Does core.async sound kind-of-like async/await? Write a checkmark in a comparison table and move on. But reality is nothing like it. Every time I have to write some JavaScript (interop) code, I am amazed that people put up with all the incidental complexity. I mean, just recently I had to implement three different ways of accessing data which was essentially in an array. Three various pieces of imperative code with iteration. In ClojureScript that would have been zero code, because everything that is "array-like" can be accessed as a seq. That sort of thing does not come up in superficial comparisons.
- Scarbutt 8y agoI agree, Clojure is technically superior in almost every way when compared to JS IMO, and would much prefer to write Clojure than JS. My poor formulated point was that, sometimes the ecosystem is more important. An experienced dev that already knows how to do everything in the domain he's working on won't have much trouble with Clojure, but you don't always know how to do some things and this is were ecosystem(third party APIs, docs, books, libs, forums, etc...) helps greatly. Also for Clojure and Clojurescript you need to at least have some good level read proficiency in Java and Javascript.
- agumonkey 8y agolots of research about the subject lots https://duckduckgo.com/?q=pattern+matching+compilation&atb=v119-3__&ia=web https://duckduckgo.com/?q=pattern+matching+compilation&atb=v... David Nolen publicly used some paper about optimized PM
- mindslight 8y agoI don't think pointing the way to a better understanding of the problem is arrogance, especially when these type of posts effectively just add to other learners' misunderstandings. I can tell the poster is still learning due to that title, and because they call a switch statement on constants "typical" (as opposed to seeing it as a broken implementation of match). The fundamental issue is called the "expression problem", and arises because the problem of assigning behavior is two dimensional (one dimension is the types/cases, the second dimension is the methods/operations), and possibly open along either dimension. Match works better when the methods/operations are open. Objects work better when the types/cases are open. If they're both open, then you need to figure out which one to make less open. At best, you can carve off partial sections where one particular dimension is open by fixing the other dimension, etc. CLOS kind of punts and has you express each element of the matrix on its own. Which doesn't actually solve the problem, but at least makes it symmetrical. That is the state of the art, AFAIK. Fixing the problem along either dimension is enough to make a workable language, but neither one is "better". There could be something better, but we haven't found it, and we're certainly not going to find it if people don't appreciate the whole problem!
- AnimalMuppet 8y agoHmm. It seems to me that you failed at the "arrogant" part.