Skip to content

Instantly share code, notes, and snippets.

View simonask's full-sized avatar

Simon Ask Ulsnes simonask

View GitHub Profile
IRCBot: class {
initialize: (server, channel, nick) {
.server, .channel, .nick: server, channel, nick
}
connect: () {
.socket: /* blablabla */
}
send_message: (msg) {
str: load_input // or whatever -- we have a string with newline-separated words
// The worker task for mapreduce
calculate_length_task: (task) {
message: task.pop // Blocks until there is a message
if message = "get_length" // Operator = overloaded for Message class
task.yield message.args[0].length
else
task.yield null
end
MyBase: class {
.some_method: (a) {
return a + 2
}
}
MyObject: class {
.prototype: MyBase
// Method 1
monkey_patch: {
.my_new_method: () { lol }
}
if MyObject
MyObject.instance_eval &monkey_patch
else
MyObject: class &monkey_patch
end
c = new Compiler({
debug: "gcc -O0 -g -Werror -Wall blabla",
release: "gcc -Os -march=blabla blabla",
});
c.add_files("*.c");
c.build();
Muh: class {
.==: [other] { return self == other }
do_something(.==)
do_something .==
}
lals: [a, b] {
return [muh] { muh + a + b }
}
print lals(2, 3)(9) // => 14
lalala: {
throw "Hejsa"
}
muh: [] {
try
lalala
catch x if String ~ x
print("caught " + x)
try
// do something
catch x
// Handle exception
else
// An exception did not occur, or was not handled
finally
// Executed afterward in any case
end
Enumerate: Object
Enumerate.__call__: [index] { index or self }
Horse, Cow, Sheep, Chicken: Enumerate
print Horse, Cow, Sheep, Chicken
== Output ==