Skip to main content
Skip to content

Lesson 3 of 12

Data types: numbers, text, sahi/galat and khali

Meet the six kinds of values AltFLang understands and the helpers that check and convert them.

8 min

The six kinds of values

Numbers such as 10, 3.5 and -7 are one type — AltFLang does not separate whole numbers from decimals. Text in quotes is a string. sahi (true) and galat (false) are the two yes/no values. khali means "nothing here". Lists hold many values in order, and objects hold named values. Lists and objects get their own lessons.

The built-in prakar(x) tells you the type of a value, and answers in Hinglish: sankhya, shabd, sahi_galat, khali, suchi, vastu or karya.

Expected output

Press Run to try it

sankhyashabdsahi_galatkhalisuchivastu

Text and numbers are different

"5" with quotes is text; 5 without quotes is a number. The + sign adds two numbers, but as soon as either side is text it joins them instead. That is handy for building messages and surprising when you meant to do maths.

Use sankhya(x) to turn text into a number and shabd(x) to turn anything into text. If the text is not a number, sankhya gives 0 rather than crashing.

Expected output

Press Run to try it

10551099 problems0

Truthy and falsy

Conditions in agar and loops do not need a real sahi or galat. These count as false: galat, khali, 0 and the empty string "". Everything else counts as true — including an empty list []. You will use this rule constantly in the next lessons.

Practice exercise

The variable umar holds the text "19". Convert it to a number, add 1, and print Agle saal: 20. Then print the type of the converted value (it should print sankhya).

Expected output

Agle saal: 20
sankhya
Open in playground
Show solution
solution.altf
rakho umar = "19";
rakho asli = sankhya(umar);
bol("Agle saal:", asli + 1);
bol(prakar(asli));