Skip to content

Instantly share code, notes, and snippets.

@vladimir-vg
Created April 8, 2011 11:40
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 vladimir-vg/909680 to your computer and use it in GitHub Desktop.
Save vladimir-vg/909680 to your computer and use it in GitHub Desktop.
Alonzo syntax example
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