user-interface, discovery-system |
# This process is spawned with two pids as arguments
# If either pid halts, I halt too.
user-interface.link
discovery-system.link
user-interface.subscribe(when(
text-entered: { message |
# I entered a message in the UI, announce it to everyone subscribed to me
my-actor.announce('exclaimed, message)
}
))
discovery-system.subscribe(when(
peer-discovered: { name, peer |
# Discovery system located another user in the chat room
# Send message to user-interface showing a Growl style notification.
user-interface << ('notify, "{name} arrived.")
peer.subscribe(when(
# This guy went away - "halted" is announced when a process stops
halted: { result | user-interface << ('notify, "{name} left.") }
# This guy said something
exclaimed: { message | user-interface << ('text-append, "{name}: {message}") }
))
}
)
main.loopuser-interface and discovery-system are two hypothetical processes whose pids (process identifiers) are passed in to this process as arguments. user-interface would be responsible for creating a window with a text display area and a text entry box. discovery-system would use our remote service discovery model to find others chatting in the same "room."
Immutability such is an important part of Spin's messaging model that we wanted a consistent way to declare an immutable construction.
# An immutable string (or symbol)
'foo
# An immutable list
'[ 1, 'foo, '[] ]
# An immutable map
'{ foo: 1, y: 'two, z: '[ 'three ] }
Slightly more advanced... # Also an immutable string
"foo with spaces"
# An immutable pair
"bar" -> 2
# Syntactic sugar for that same pair
bar: 2
# Syntactic sugar for "baz" -> baz
~baz