Blog Categories
Ad Space
Twitter Updates
Currently Reading
Powered by Squarespace
Git Projects
« Why do you dislike me Apple? | Main | Adding Erlang library locations »
Friday
21Nov

A knock knock joke

Just a quick one in the morning.

-module(knockknock).
-compile(export_all).

start_joke() ->
    register(person_1, erlang:spawn(knockknock, person1, [])),
    register(person_2, erlang:spawn(knockknock, person2, [])),
    person_1 ! start_joke.

relay(Person, Message) ->
    io:format("------- ~p -------~n", [Message]),
    Person ! Message.

person1() ->
    receive 
        start_joke ->
            relay(person_2, "Knock, Knock");
        "Who's There?" ->
            timer:sleep(100000),
            relay(person_2, "Java")
    end,
    person1().

person2() ->
    receive
        "Knock, Knock" ->
            relay(person_1, "Who's There?");
        "Java" ->
            relay(person_1, "Ha Ha")
    end,
    person2().

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>