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