Hacker News new | ask | show | jobs
by antirez 4518 days ago
Smalltalk's "become" is a pretty interesting one... http://gbracha.blogspot.it/2009/07/miracle-of-become.html
2 comments

Akka actors have a very similar feature, same name. It doesn't swap identities though.

It's actually pretty cool if you think of it as a way to track state without having a mutable variable.

One example is this implementation of the dining philosophers problem:

https://github.com/akka/akka/blob/master/akka-samples/akka-s...

You can also use "unbecome" and effectively treat an actor's behavior as a stack, popping and pushing receive functions. One cool trick is to bind a value to your receive function:

  def receive(foo: Foo): Receive = { ... }
Then you can bind immutable data to a given receive function but think of it as mutable by replacing the current receive function with become().
Smalltalk also is rather famous for giving developers enough freedom to more or less destroy the environment with the terrifying looking command "Smalltalk := nil"
I once crashed Squeak by making true := false. It was an interesting experience.