logoalt Hacker News

cess11 • today at 11:38 AM • 2 replies • view on HN

"We need a way to send a request to another actor, and provide it a way to send back a response that can be connected to the original request. For that, we have a “reply slot”, represented as a ReplyTo<R> in the code for actors."

It's probably partly due to habit but I like the BEAM solution to this, i.e. provide your sender ID and let the receiver figure it out. Oftentimes you don't care about a response, you just want to flick a switch at a distance or throw some garbage into a bucket.

For me it makes the basic model simpler to hold in my mind and it's been a nice learning experience to look at how stuff on the BEAM gets from there to state machines and generic servers and supervisors and so on.

One of the nicest things with the BEAM is that it feels like I have an OS available when programming. I don't get that with threading in e.g. Java, and I don't think I'd get it from Golang either.

Does Rust have pattern matching on function declarations? I.e. could the match-block be switched for several handle-functions instead in the example? If not, then I think I prefer the BEAM way there too, it's quite nice to break out the message handlers into functions matching on the message instead of going through a match/case and then into the actual handlers.

The preemptive multitasking on the BEAM is convenient too, it almost always gives the result I want.

I don't see an example in TFA of how the actors are addressed, do they get a number when instantiated or somesuch and then one does like a send-syscall with that number?


Replies

pjmlp • today at 12:27 PM

> One of the nicest things with the BEAM is that it feels like I have an OS available when programming. I don't get that with threading in e.g. Java, and I don't think I'd get it from Golang either.

I certainly feel like that when doing Java and .NET runtimes, Java especially is what made me stop caring about POSIX.

Both are the closest I have been able to do in mainstream to the OS abstraction layers, past my Smalltalk and Lisp experiences.

kibwen • today at 11:55 AM

> Does Rust have pattern matching on function declarations?

Rust supports patterns in function declarations, but not for the purposes you're thinking of. In function arguments, patterns are required to be irrefutable, so no redeclaring a function with different refutable patterns each time. Rust only wants a single source of truth for each function (possibly attributable to an allergy of anything that could be mistaken for C++-style function overloading), and since Rust pointedly declines interprocedural type inference, redeclaring your function multiple times with full type annotations every time would just be more verbose anyway (in contrast to something like Haskell, which supports what you're asking for but allows type inference in function signatures).