Last active
August 29, 2015 14:11
-
-
Save justinmchase/edc1bd6dced22d6349bb to your computer and use it in GitHub Desktop.
A hypothetical compositional language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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