Akka-examples | These examples are purely meant to illustrate
kandi X-RAY | Akka-examples Summary
kandi X-RAY | Akka-examples Summary
These examples are purely meant to illustrate the posibilities of Akka. We tried to make these examples as simple as possible. The disadvantage was that we had to use some less nice constructions. If you want some more real life examples and best practices than we advice you to look at the official Akka examples.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Akka-examples
Akka-examples Key Features
Akka-examples Examples and Code Snippets
Community Discussions
Trending Discussions on Akka-examples
QUESTION
I'm trying to emulate a simple functional language using actors.
Actor systems nowadays are used basically for speeding up all kind of stuff by avoiding OS locks and stalled threads or to make microservices less painful, but initially it was supposed to be an alternative model of computation in general [1][2] and therefore should be capable to cover any programming language construct and certainly an if
, right?
While I'm aware that this is occasionally met with irritation, I saw one timid attempt to move towards recursive algorithms represented using akka actors (I've refurbished it and added further examples including the one given below). That attempt halted at function calls, but why not go further and also model operators and if conditions with actors? In fact the smalltalk language applies this model and yields a precursor of the actor concept, as has been pointed out in the accepted answers below.
Surprisingly recursive function calls aren't much of an issue, but if
1 is, due to it's potentially stateful nature.
Given the clause C: if a then x else y
, here's the problem:
My initial idea was, that C
is an actor behaving like a function with 3 parameters (a,x,y)
that returns either x
or y
depending on a
. Being maximally parallel [2] a,x
and y
would be evaluated simultaneously and passed as messages to C
. Now, this isn't really good, if C
is the exit condition of a recursive function f
, sending one branch of f
in an infinite recursion. Also if x
or y
have side effects one can't just evaluate both of them. Let's take this recursive sum (which is not the usual factorial, stupid as such and could be made tail recursive, but that's not the point)
ANSWER
Answered 2019-Oct-10 at 10:50Q : didn't ( I ) miss out on the question at a fundamental level?
Yes, you happened to have missed a cardinal point: even the functional-languages, that may otherwise enjoy the forms of AND- and/or OR-based fine-grain sorts of parallelism, do not grow as wild as not to respect the strictly [SERIAL]
nature of the if ( expression1 ) expression2 [ else expression3 ]
You have spend many efforts on argumentation about recursion-case(s) whereas the principal property was left out of your view. State-fullness is the Mother Nature of the computing ( these toys are nothing but finite state automata, no matter how large the state-space might be, it is and always will principally remain finite ).
Even the cited Scala p.88 confirms this: "The conditional expression is evaluated by evaluating first e1. If this evaluates to true
, the result of evaluating e2 is returned, otherwise the result of evaluating e3
is returned." - which is a pure-[SERIAL]
process-recipe ( one step after another ).
One may remember, that even the evaluation of expression1
may have (and does have ) state-change effects ( not only "side-effects" ), but indeed state-change effects ( PRNG-steps into a new state whenever a random-number was asked to get generated and many similar situations )
Thus the if e1 then e2 else e3
has to obey a pure-[SERIAL]
implementation, no matter what benefits may be brought into action from fine-grain {AND|OR}-based-parallelism ( may see many working examples thereof in languages that can use 'em right since late 70-ies early 80-ies )
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Akka-examples
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page