5 ms·
A sample from their user manual[0]: % print even numbers between 1 and 10 main :- count(1). count(11). count(N) :- N =< 10 | even(N), N2 is N
by simplify 5y ago
A sample from their user manual[0]:
% print even numbers between 1 and 10
main :- count(1).
count(11).
count(N) :- N =< 10 | even(N), N2 is N + 1, count(N2).
even(N) :- M is N \\ 2, even(M, N).
even(0, N) :- writeln(N).
even(_, _) :- otherwise | true.
[0] http://www.call-with-current-continuation.org/strand/MANUAL http://www.call-with-current-continuation.org/strand/MANUAL
- rad_gruchalski 5y agoLooks very similar to erlang, for sure the devil is in details but it’s quite easy to read when applying erlang line of thought to it.
- pfraze 5y agoErlang was originally built from Prolog, I believe.
- QuinnWilton 5y agoYup! The original Prolog implementation is described in "Use of Prolog for developing a new programming language" [0], and took place in 1986. After performance eventually became an issue, they cross-compiled Erlang to a few other concurrent languages (Strand included), before opting to directly implement Erlang in C. [0] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.3972 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.3...
- QuinnWilton 5y agoJoe Armstrong and Robert Virding actually experimented with compiling Erlang to Strand. I'm not familiar with all of the details, but I believe they saw a factor of six speedup as compared to the Prolog implementation [0], but deemed the project a failure because of the complexity involved in restricting Strand's parallelism and failure to meet their target of a 70x speedup [1]. I'm actually sharing this in the first place because I managed to acquire a copy of "Strand: New Concepts in Parallel Programming" [2] yesterday, and it includes a case study about the Erlang -> Strand compiler, so I've been having fun trying to piece together the lineage. [0] https://erlang.org/download/armstrong_thesis_2003.pdf https://erlang.org/download/armstrong_thesis_2003.pdf [1] http://erlang.org/pipermail/erlang-questions/2007-September/028864.html http://erlang.org/pipermail/erlang-questions/2007-September/... [2] https://www.amazon.com/Strand-New-Concepts-Parallel-Programming/dp/013850587X https://www.amazon.com/Strand-New-Concepts-Parallel-Programm...
- QuinnWilton 5y agoWhat isn't clear from this snippet, that I think is incredibly cool, is that all of the expressions within a function (here, called processes), actually run in parallel. In this snippet: count(N) :- N =< 10 | even(N), N2 is N + 1, count(N2). count(N) is defined defined as a process that takes an argument named N, and if N is less than or equal to 10, the process changes state to a random process on the right side, and is also forked to become the other two processes. Where it gets weird, is that the resulting three processes have data dependencies between them, so if the third process were executed first, count(N2), the dependency on N2 wouldn't be satisfied, and so that process would suspend, and a new process be chosen for execution. It's easy to look at this line of code and think that the three expressions will execute in the order they're written, but any interleaving of them is possible, with that sort of non-determinism being built into the language by design. I'm currently reading the Strand book, and it more or less describes the language as being Prolog, but without unification and backtracking: instead treating dataflow as being the basis for the computational model.
- 082349872349872 5y agoIt would be interesting if current computers could take advantage of all expressions running in parallel; back last century that was exposing more parallelism (and incurring more coordination costs) than a better, coarser-grained, approach.
- kevin_thibedeau 5y agoThis is effectively what happens when HDLs are compiled into an ASIC or FPGA.
- harperlee 5y agoI guess that this being a declarative language, it is the task of the compiler to determine the cutoff where you just reorder tasks or you spawn a thread, right?
- bitforger 5y agoCan you share your copy of the Strand book? A cursory Google search makes it seem somewhat elusive...