စံကား

04Variables

Names

What a variable name can contain, and names in backticks.

The programmer chooses the name of each variable and constant. A good name tells what the value means: အသက် (age) is better than က.

A name can use Burmese letters, other scripts, digits (not first), _, and even emoji. Upper and lower case are different: Age and age are two names.

စံကား

Expected output

၁၁၆

Where a name ends

A name ends at a space, or at a sign such as + or ။. A change of script does not end it: အသက်age and age၂ are names too, one word each.

စံကား

Expected output

၂၀

That is the reason a name needs a space before a particle. ageကို is one long name, not the name age and the particle ကို, so the verb finds no particle:

စံကားZK0206

Expected error

error[ZK0206]: "ပြသပါ" needs "ကို|ဟု" after operand 1, found no particle
  = help: write "age ကို" with a space: a name joined to a particle is read as one word

Write age ကို and အသက် ကို, with a space (see Spaces between words).

Names that look like Zaka words

A name cannot be made of Zaka's reserved words alone. Short words such as ကြီး (greater), ငယ် (less) and ညီ (equal) are reserved verbs, so ကြီး alone cannot be a name; ကြီးသူ can. တန်ဖိုးကို reads as the two reserved words တန်ဖိုး + ကို. The Reserved words page lists them all. To use such a name, or a name with spaces in it, wrap it in backticks:

စံကား

Expected output

၇
၉၀

Backtick names work, but are hard to read. Save them for when nothing else will do.

Each name once

In one place, a name can be declared once and no more:

စံကားZK0302

Expected error

error[ZK0302]: "အသက်" is declared before in this scope

The help line suggests declaring the name again "in an inner block". The next page, Blocks and scope, explains what that means.

Hands on

  • Declare a variable named with a favourite emoji and print it.
  • Test ကိန်းရှင် ၂အသက် သည် ကိန်းပြည့် ဖြစ်၍ တန်ဖိုးသည် ၁ ဖြစ်ပါစေ။. What stops a name from starting with a digit?

Next: Blocks and scope.