Getting startedSlide 6 of 86
6NameGetting started

Names have shapes

A name's spelling says what it is, and each shape is enforced where the name is declared:

  • camelCase names variables, parameters, fields, every proc, func and query, and the name an import is reached through.
  • PascalCase names types, their variants, and atoms.
  • UPPER_CASE may name a variable nothing reassigns, the usual spelling for a constant. It is allowed, never required, and a mut variable, a parameter, a field, a loop counter or a name a pattern binds may not use it.

A leading _ is set aside before the shape is checked, so _scratch and _MAX are fine, and _ alone throws a value away. Names use only ASCII letters, digits and _; café is not a name.

The keywords are import proc func query test law type if else return is with void true false echo assert panic dyn mut async await for in each bounds break continue switch. axiom is reserved for a later version: it means nothing yet, and any use of it is an error. Only the lower-case spelling is reserved, so Proc, IF and proC are ordinary names: a variant may be called Return and a type Test, but a field may not be called type. A field whose JSON key is a keyword takes another name and gives the key in an annotation, shown on the slide on field annotations.

type Shape {                  // a declared type, met properly later on
	Circle { radius: Int }
}

proc main(): void {
	name := "bee"             // camelCase: a variable
	MAX_RETRIES := 5          // UPPER_CASE: a variable nothing reassigns
	shape := Shape.Circle(4)  // PascalCase: a type and its variant
	_scratch := 0             // a leading _ is set aside

	echo "{name}, retry up to {MAX_RETRIES} times, radius {_scratch + 4}"
	echo shape                // {4}: a value shows as its fields
}