Skip to content

Identifiers

Woodrow Barlow edited this page Dec 7, 2017 · 7 revisions

Definition

An Identifier token can represent the name of a variable, constant, function, isr, struct, or unit.

When an identifier is defined for the first time, it should follow one of the following keywords: let, constant, fun, isr, struct, or use. In some cases, an optional storage class is allowed between the keyword and the identifier.

An identifier can be referenced at statement level except in the global scope or within an expression.

The type of a variable (or the return type of a function) is not considered part of the identifier.

Rules

A valid identifier follows these rules:

  • Begins with an alpha character (e.g., a letter, uppercase or lowercase, as recognized by Python 3's .isalpha() function).
  • Must not contain any of these special characters: (, ), [, ], :, ., ,, ", \.

Discouraged Practices

The following characters are discouraged in identifiers because they will likely be added to the list of special characters:

  • @, &, {, }

The following characters are discouraged because they commonly represent things in other languages (and therefore harm code readability and break syntax highlighters):

  • ;, `, ', |

Encouraged Practices

The following naming conventions are encouraged in order to help with code readability:

  • Use lower case for all identifiers.
  • All multi-word identifiers are kebab-case (e.g., separated by a - character). For example, loop-counter = 0 or perform-operation().

The following additional function naming conventions (inspired by Ruby-lang) are encouraged (but not enforced or even recognized by the compiler) in order to designate certain behaviors:

  • End a function identifier with a ? to designate it as a "predicate". A predicate function tests and returns a condition related to its parameters, but does not change program state. For example, value-in-list?(list, value).
  • End a function identifier with a ! to designate that it modifies the value of its parameters directly. For example, sort-list!(list).

Note that the ? convention eliminates the need for predicates like is- on function identifiers.