Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * PingPong.abs -- PingPong example
- *
- */
- module PingPong;
- data PingMsg = Fine
- | HelloPing
- | ByePing
- ;
- data PongMsg = NoMsg
- | Hello(Ping)
- | HowAreYou
- | ByePong
- ;
- interface Ping {
- Unit ping(PingMsg m);
- }
- interface Pong {
- Unit hello(Ping ping);
- Unit pong(PongMsg m);
- }
- class PingImpl(Pong pong) implements Ping {
- Unit run(){
- pong!hello(this);
- }
- Unit ping(PingMsg msg){
- PongMsg reply = case msg {
- HelloPing => HowAreYou;
- Fine => ByePong;
- // ByePing => NoMsg;
- };
- if (reply != NoMsg) {
- println("Pinging with: " + toString(reply));
- Fut<Unit> fu = pong!pong(reply);
- fu.get;
- } else {
- println("NoMsg");
- }
- }
- }
- class PongImpl implements Pong {
- Ping ping;
- Unit hello(Ping ping) {
- this.ping = ping;
- println("Hello");
- ping!ping(HelloPing);
- }
- Unit pong(PongMsg msg){
- if (msg == HowAreYou) {
- println("Fine");
- ping!ping(Fine);
- }
- else {
- println("Bye!");
- ping!ping(ByePing);
- }
- }
- }
- {
- Pong pong = new PongImpl();
- new PingImpl(pong);
- }
- /*
- ================ Output if run in Erlang ================
- Start m_PingPong
- Hello
- Pinging with: HowAreYou
- Fine
- Pinging with: ByePong
- Bye!
- Uncaught PatternMatchFailException in method ping and no recovery block in class definition, killing object PingPong.PingImpl:<0.71.0>
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement