Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.