Created
July 1, 2012 00:47
-
-
Save erincandescent/3026266 to your computer and use it in GitHub Desktop.
Yaay
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
// Hello world | |
print "Hello world"; | |
// Some maths | |
// assign min & max as module scope variables | |
max = {(a, b) ^a > b? a : b}; | |
min = {(a, b) ^a < b? a : b}; | |
// ^ means return | |
// a & b will be new local variables | |
@a = max(x, y); | |
@b = min(x, y); | |
// Let us create a class... | |
class #Kitty { | |
__slots = (#name,) | |
__init = {(self, name) self.name = name }; | |
__str = {(self) ^"Cat " .. self.name }; | |
__repr = {(self) ^"<" .. self.__str! .. ">" }; | |
meow = {(self) print self.name .. " meows" }; | |
purr = {(self) print self.name .. " purrs" }; | |
}; | |
@faith = Kitty "Faith" | |
faith.meow! | |
// Faith meows | |
@purr = faith.purr | |
print typeof purr | |
// <BoundMethod on Cat Faith> | |
purr! | |
// Faith purrs | |
// Some vector maths... | |
@a = Vec(1, 2, 3, 0); | |
@b = Vec(10, 20, 30, 0); | |
@dot = a * b; | |
@cross = a ** b; | |
// How about a matrix? | |
@I = Matrix[4, 4] | |
(1, 0, 0, 0 | |
0, 1, 0, 0 | |
0, 0, 1, 0 | |
0, 0, 0, 1); | |
// Of course, we could have just done... | |
I = Matrix[4, 4].identity; // or | |
I = Matrix[4, 4].I; | |
print I; | |
// Matrix[4](1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) | |
// Matrix[4] -- huh? We asked for [4, 4]! | |
// The Matrix "cluster" will square matrixes with only one index. | |
// We could in fact have asked for Matrix[4] | |
// Maybe something different | |
@A = Matrix[1, 4](0, 1, 2, 3) | |
print A | |
// Matrix[1, 4](0, 1, 2, 3) | |
print A.transpose! | |
// Matrix[4, 1](0, 1, 2, 3) | |
// Maybe you're slightly curious... | |
print typeof typeof | |
// <Function@0x...> | |
// Yes, typeof is a function! | |
// Inheritance? Yup | |
class #Food { | |
__init = {(self, type) self.type = type }; | |
} | |
class #Cake (Food) { | |
__init = {(self, type) super(Cake, self).__init(type .. " Cake")}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment