Skip to content

Instantly share code, notes, and snippets.

View simonask's full-sized avatar

Simon Ask Ulsnes simonask

View GitHub Profile
/*
Snow Private Methods
*/
SomeClass: class() {
private_method: [arg] {
print(arg)
}
.initialize: [arg] {
Foo: class() {
.attribute("bar", get: { [z]{print(z)} })
}
foo: Foo()
foo.bar(123) //=> output "123"
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) })
}
PrimeGenerator for new, experimental Snow syntax
-------------8<-----------------
PrimeGenerator: {
return [idx] {
.cache: .cache? || @()
cached: .cache(idx)
return cached if cached
PrimeGenerator: {
return [idx] {
.cache: .cache? || @
cached: .cache(idx)
return cached if cached
max: .cache.last || 2
is_prime: [n] {
Enumerate: Object
Enumerate.__call__: [index] { index or self }
Horse, Cow, Sheep, Chicken: Enumerate
print Horse, Cow, Sheep, Chicken
== Output ==
try
// do something
catch x
// Handle exception
else
// An exception did not occur, or was not handled
finally
// Executed afterward in any case
end
lalala: {
throw "Hejsa"
}
muh: [] {
try
lalala
catch x if String ~ x
print("caught " + x)
lals: [a, b] {
return [muh] { muh + a + b }
}
print lals(2, 3)(9) // => 14
Muh: class {
.==: [other] { return self == other }
do_something(.==)
do_something .==
}