6 ms·
Prolog and Erlang in the same thread - is it Christmas already? Two of my favourite languages, both hugely undervalued. I remember the moment I first "got" Pr
by spinningslate 8y ago
Prolog and Erlang in the same thread - is it Christmas already? Two of my favourite languages, both hugely undervalued.
I remember the moment I first "got" Prolog. Having only programmed in C/C++ to that point, it took some mental contortion. But the "oh!" moment was amazing. Backward chaining & logical variables are just so incredibly elegant. I still use transitive closure as an example of just how powerful the language is:
path(A, B) :-
link(A,B).
path(A, B) :-
link(A,I), path(I,B).
That's it. Stunningly simple.
As for Erlang - as others have noted - it was conceived right from the start as a language for concurrency. It's had 20 years to mature and robustly solve problems that inherently single-threaded languages have barely even recognised yet (C/C++/Java/C#/python/javascript/rust/...). Supervisors / error handling and threading are two notable examples. It makes me sad to look at the spread of "async". An inelegant sticking plaster that adds yet another concurrency construct and turns it into a tactical decision - on every method - and at the call site too.
Erlang shows that a single, well-conceived and executed construct is both possible and preferable. Lovely.
- simplify 8y agoCan you explain what transitive closure is and how your prolog snippet accomplishes it?
- carapace 8y agohttps://en.wikipedia.org/wiki/Transitive_closure#In_graph_theory https://en.wikipedia.org/wiki/Transitive_closure#In_graph_th... > In computer science, the concept of transitive closure can be thought of as constructing a data structure that makes it possible to answer reachability questions. That is, can one get from node a to node d in one or more hops? A binary relation tells you only that node a is connected to node b, and that node b is connected to node c, etc. That snippet defines a function path(A, B) by specifying two cases: 1. a link(A, B) exists -or- 2. some element I exists, such that a link(A, I) exists and path(I, B) exists.
- dnautics 8y agoAsync is terrible as a primitive, but as sugar on top of real concurrency, it's not terrible. I use Task.Supervised.async() all the time in elixir, with confidence that I have access to all the parts that I might need for diaster recovery if I should need it later.
- cjallen88 8y agoYou might be interested in the idea of Web Prolog, a language being written by Torbjorn Lager. It aims to provide similar concurrency features as Erlang, but retaining the logic variables, backtracking and unification etc provided by standard prolog. It's at a point where he needs feedback. https://www.youtube.com/watch?v=mmNvxDEaLO4 https://www.youtube.com/watch?v=mmNvxDEaLO4