Skip to content

Instantly share code, notes, and snippets.

@justinmchase justinmchase/Components.js
Last active Aug 29, 2015

Embed
What would you like to do?
A hypothetical compositional language
component c1 {
function receive(message: string) { // handles "receive" messages
print(message)
}
}
component c2 {
var running: bool
function run() { // Handles the "run" message
if(!running)
running = true
this->receive("hello world!") // Sends a message to "receive" with an argument
else
this->receive("error!")
}
}
// An object containing the above components
var x = {
c1 = new c1()
c2 = new c2()
}
// send a message to components on x named "run"
x->run() // > hello world!
x->run() // > error!
var x = { } // an empty object
var y = {
value: "hi" // any value type, not a function
}
var z = Root { // a named object
}
var j = Root { // An object with children
First {
}
Second {
}
}
for(var child in j) {
print(child.name) // First, Second
}
j.First.foo() // Get child named "First" send it a message named "foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.