Syntax: Names
● Beginner3 min
Names are made of letters, digits and _, in snake_case for values and PascalCase for types.
type OrderStatus = Pending | Paid
fn main() {
const total_price = 499
const नाम = "Asha"
const status = OrderStatus.Paid
print("{नाम} owes {total_price}: {status}")
}The program ran and printed:
kavach run names.kav
Asha owes 499: Paidsnake_casefor variables, functions and modules:total_price.PascalCasefor types and their variants:OrderStatus,Paid.- Letters from any script work:
नामis a fine name. A name can't start with a digit.
The compiler enforces the style, and says exactly what to write:
fn main() {
const totalPrice = 499
print(totalPrice)
}The compiler refused the program:
kavach run names-style.kav
error: variables use snake_case: write `total_price`You rarely see this error: kavach fmt renames the name and every use of it for you.