Skip to content

Instantly share code, notes, and snippets.

View simonask's full-sized avatar

Simon Ask Ulsnes simonask

View GitHub Profile
PrimeGenerator: {
return [idx] {
.cache: .cache? || @
cached: .cache(idx)
return cached if cached
max: .cache.last || 2
is_prime: [n] {
PrimeGenerator for new, experimental Snow syntax
-------------8<-----------------
PrimeGenerator: {
return [idx] {
.cache: .cache? || @()
cached: .cache(idx)
return cached if cached
SomeGenericClass: class(ThePrototype) {
.initialize: [a] {
.a: a
}
.attribute("attr", get: { .a }, set: { .a: it })
// Maybe this?
.attribute("a", get: { .get_member("a") }, set: { .set_member("a", it) })
}
Foo: class() {
.attribute("bar", get: { [z]{print(z)} })
}
foo: Foo()
foo.bar(123) //=> output "123"
/*
Snow Private Methods
*/
SomeClass: class() {
private_method: [arg] {
print(arg)
}
.initialize: [arg] {
tIDENTIFIER = tNORMAL_IDENTIFIER | tOPERATOR_IDENTIFIER
tNORMAL_IDENTIFIER = [\w][\w\d*]*
tOPERATOR_IDENTIFIER = [\+\-\*\/\\]*
tOPERATOR_CALL = tIDENTIFIER tIDENTIFIER tIDENTIFIER
tNORMAL_CALL = tIDENTIFIER tDOT tSTART_PAREN tARG_LIST tEND_PAREN
tEXPR = ... | ... | tOPERATOR_CALL | tNORMAL_CALL | ... | ...
SomeClass: class() {
.initialize: { ... }
}
foo: SomeClass()
bar: SomeClass()
foo.lol: { print "HELLO" }
bar.lol() // => ERROR
foo.lol() // => "HELLO"
Mutexed: class {
.initialize: [closure] {
.closure: closure
.mutex: Mutex
}
.(): [*args] {
.mutex.lock
.closure(*args)
.mutex.unlock
window: Window("Test") {
.button1: Button("Lol") { print "HELLO WORLD" }
}
window.show
window.button1.click
window.on_close << { print ":(" }
void whatever(Object* raw_ptr) {
Handle<Object> ptr = raw_ptr; // bookkeeping pointer
ptr->lals();
return;
// ptr destroyed, book kept
}