Syntax Paradigm
Alia supports multi-paradigm programming; this document describes the standard paradigm.
1. Newline Termination
The statement separator '\n' is equivalent to ';'; in the standard paradigm, statements are terminated by newline characters.
The following code snippet conforms to the standard paradigm:
const name = 'Alia'
const version = 0.1
The following code snippet does not conform to the standard paradigm:
const name = 'Alia';
const version = 0.1;
2. Explicit Types
<Dynamic> is the dynamic type; in the standard paradigm, type constraints are explicit types.
The following code snippet conforms to the standard paradigm:
const name = 'Alia'
const count: Number = 42
const items: Array = [1, 2, 3]
The following code snippet does not conform to the standard paradigm:
const name: Dynamic = 'Alia'
3. Single-Line Folding
Non-Stack statements take a single-line form, and Stack blocks containing a single instruction take a single-line form.
The following code snippet conforms to the standard paradigm:
const sum = a + b
const double = alias <Number n> -> { n * 2 }
const calculate = alias <Number a> and <Number b> -> {
const sum = a + b
const product = a * b
sum + product
}
4. Space Indentation
The character for hierarchical indentation is the space character.
The following code snippet conforms to the standard paradigm:
const Person = *[
name: '',
age: 0,
greet: alias -> { 'Hello, ' .. self.name }
]
The following code snippet does not conform to the standard paradigm:
const Person = *[
name: '',
age: 0
]
5. Space Separation
Explicit spaces exist between operands and operators.
The following code snippet conforms to the standard paradigm:
const sum = a + b
const product = x * y
const result = value1 + value2 * value3
The following code snippet does not conform to the standard paradigm:
const sum=a+b
const product=x*y
6. Semantic Joining
The formal parameter list of an alias declaration includes auxiliary keywords; auxiliary keywords join the semantics of formal parameters, and and and with are auxiliary keywords.
The following code snippet conforms to the standard paradigm:
alias add <Number a> and <Number b> -> { a + b }
alias greet <String name> with <String greeting> -> { greeting .. ', ' .. name }
print add 1 and 2
print greet 'Alice' with 'Hello'
7. Implicit Return
A return value at the end of a stack is exempt from the return keyword; a falling value is treated as a return.
The following code snippet conforms to the standard paradigm:
const square = alias <Number n> -> { n * n }
const max = alias <Number a> and <Number b> -> { a > b ? a : b }
The following code snippet does not conform to the standard paradigm:
const square = alias <Number n> -> { return n * n }
Complete Example
The following code snippet conforms to the standard paradigm:
class Person *[
name: '',
age: 0,
greet: alias -> { 'Hello, ' .. self.name },
new: alias named <String name> aged <Number age> -> {
self.name = name
self.age = age
self
}
]
alias add <Number a> and <Number b> -> { a + b }
alias multiply <Number a> and <Number b> -> { a * b }
const person = new Person named 'Alice' aged 30
print call person.greet
print add 10 and 20
print multiply 5 and 3