Skip to content

Instantly share code, notes, and snippets.

@mazur
Created March 18, 2011 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mazur/875813 to your computer and use it in GitHub Desktop.
Save mazur/875813 to your computer and use it in GitHub Desktop.
For fun and fun
; This is a comment
; Everything that is declared "outside" a class is automatically placed in the class "Global"
this_is_a_variable: 5
; Types are not dynamic, they are inferenced.
this_is_a_method: (x, y) {
result: x + y; Everything after ; is not read and treated like a comment
return result; Methods don't need types, they are also inferenced
}
this_is_another_method: () {
; This will generate two overrides of "this_is_a_method"
; one with int and one with string
Global.this_is_a_method(5, 10);
Global.this_is_a_method("foo", "bar");
; If no type is given then "Global" is assumed
this_is_a_method(5, 10);
}
class Nom {
; are comment signs and thus optional at line endings.
i_haz_a_method: (x) { return x }
}
; Classes can be re-opened and monkey patched
class Nom {
; Last statment in a method is always returned
i_haz_another_method: (x) { x }
}
class OmNom {
method_chaining_example: () {
new_method: () { print "Hello" } + () { print "World" }
}
}
; everything is an object.
some_value: 5
add_one: (x) { x + 1 }
; All objects are passed by reference
add_one(some_value)
; some_value is now 6
other_value: add_one(some_value.clone())
; some_value is still 6 since we passed a clone. other_value is 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment