Created
April 8, 2011 11:40
-
-
Save vladimir-vg/909680 to your computer and use it in GitHub Desktop.
Alonzo syntax example
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
module 'module_name, as: [ | |
Greeter = object, as: [ | |
method 'hello_world, as: [ | |
"Hello world!" | |
] | |
method 'hello, as: [ some_word | | |
"Hello #{some_word}!" | |
] | |
# getter | |
method 'var, as: [ @var ] | |
# setter | |
method 'var=, as: [ value | @var = value ] | |
# operator overloading examples: | |
method 'self[], as: [ index | | |
"something at index #{index}" | |
] | |
method 'self+, as: [ other | | |
"sum of #{self} and #{other}" | |
] | |
method 'self*, as: [ other | | |
"product of #{self} and #{other}" | |
] | |
] | |
Greeter.hello_world | |
Greeter.hello_world() | |
Greeter.hello "someone" | |
Greeter.hello("someone") | |
Greeter["index"] | |
g = Greeter.clone | |
b = Greeter.clone | |
# using operators | |
g + b * g | |
g+b*g | |
g+(b*g) | |
# operators can be placed in multiple line, but only with indentation | |
# same | |
g + b * | |
g | |
# example of dictionary pair definition | |
{ key: value } | |
# the same | |
# non-symbol keys with additional space looks like: | |
{ 'key : value } | |
{ foo: foo } | |
{ :foo } | |
{ | |
age: 18, | |
gender: male, | |
# object as key | |
Greeter : Greeter.clone, | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment