Skip to main content
Skip to content

One page · printable

AltFLang cheatsheet

Every keyword, operator and built-in function of AltFLang on one page. Keep it open next to the playground, or print it — the print layout fits on a single sheet and always prints dark text on white.

Learn step by step

Basics

// comment   # comment   /* block */
bol("Namaste", 42);   // Namaste 42
chhap("same as bol");
bol("line1\nline2\ttab");

Variablesdetails about Variables

rakho naam = "Asha";   // variable
naam = "Ravi";          // update
pakka GST = 18;         // constant
rakho x;                // khali

Values and typesdetails about Values and types

rakho n = 3.5;          // sankhya
rakho s = 'text';       // shabd
rakho ok = sahi;        // sahi / galat
rakho kuch_nahi = khali;
bol(prakar(n));         // sankhya

Falsy: galat, khali, 0, "". Everything else is truthy (even []).

agar / warnadetails about agar / warna

rakho marks = 72;
agar (marks >= 90) {
  bol("A+");
} warna agar (marks >= 33) {
  bol("Pass");
} warna {
  bol("Fail");
}

jab_tak (while)details about jab_tak (while)

rakho i = 0;
jab_tak (i < 3) {
  bol(i);
  i += 1;
}

chalo (for), bhang, aagedetails about chalo (for), bhang, aage

chalo (rakho i = 1; i <= 10; i = i + 1) {
  agar (i == 3) { aage; }   // continue
  agar (i == 6) { bhang; }  // break
  bol(i);
}

karya / lautaodetails about karya / lautao

karya jod(a, b) {
  lautao a + b;
}
bol(jod(2, 3));         // 5
rakho dugna = karya (x) { lautao x * 2; };

Lists

rakho l = [10, 20, 30];
bol(l[0], lambai(l));   // 10 3
l[1] = 25;
jodo(l, 40);            // add to end
rakho last = nikalo(l); // remove last

Objects

rakho p = { naam: "Zoya", umar: 16 };
bol(p.naam, p["umar"]);
p.shehar = "Agra";      // add a key
bol(chabiyan(p));       // [naam, umar, shehar]

Input

rakho naam = pucho("Naam?");
rakho umar = sankhya(pucho("Umar?"));
agar (naam == khali) { bol("no input"); }

pucho() returns text, or khali when input runs out.

Operators

+ - * / %
add, subtract, multiply, divide, remainder (+ also joins text)
== !=
equal / not equal (strict: 5 == "5" is galat)
< > <= >=
compare sizes
&& || !
and, or, not
= += -= *= /=
assign, or update in place

Built-ins: Output and input

bol(...values)
Prints the values on one line, separated by spaces (a statement keyword).
chhap(...values)
Alias for bol — identical behaviour.
pucho(sawal?)
Shows the question and returns the next line of input as text (khali when input runs out).

Built-ins: Types and conversion

prakar(x)
Type name: "sankhya", "shabd", "sahi_galat", "suchi", "vastu", "karya" or "khali".
sankhya(x)
Converts to a number (0 if it is not a valid number).
shabd(x)
Converts any value to text, exactly as bol would print it.
lambai(x)
Length of a list or text, or the number of keys in an object.
samay()
Current time in milliseconds since 1 Jan 1970.

Built-ins: Text

bada(text)
Text in UPPERCASE.
chhota(text)
Text in lowercase.
saaf(text)
Removes spaces from both ends of the text.
kaato(text, sep?)
Splits text into a list at every sep. Without sep it splits into words.
milao(list, sep = "")
Joins the list items into one text, with sep between them.
badlo(text, purana, naya)
Replaces every purana in the text with naya.

Built-ins: Text and lists

shamil(x, item)
sahi if the list contains item (or the text contains it), else galat.
khojo(x, item)
Position (index) of the first item in the list or text, or -1 if missing.
tukda(x, start, end?)
A piece of the list or text from start up to (not including) end. Negative counts from the end.
ulta(x)
A reversed copy of the list or text (the original is unchanged).

Built-ins: Lists

jodo(list, item)
Adds item to the end of the list (changes it) and returns the list.
nikalo(list)
Removes and returns the last item of the list (khali if it is empty).
chhanto(list)
A sorted copy of the list: numbers smallest first, anything else alphabetically.
kram(start, end, step = 1)
A list of numbers from start up to (not including) end. kram(n) counts 0 to n-1.
kul(list)
The sum of all numbers in the list (0 for an empty list).

Built-ins: Map, filter, reduce

har(list, fn)
A new list with fn(item, index) applied to every item (map).
chuno(list, fn)
A new list with only the items for which fn(item, index) is true (filter).
ikattha(list, fn, shuru?)
Combines all items into one value: fn(jama, item, index), starting from shuru (reduce).

Built-ins: Objects

chabiyan(obj)
A list of the object's keys.
mulya(obj)
A list of the object's values.

Built-ins: Maths (ganit)

ganit.PI
The number π (3.14159…).
ganit.E
Euler's number e (2.71828…).
ganit.abs(x)
Distance from zero (removes the minus sign).
ganit.floor(x)
Rounds down to a whole number.
ganit.ceil(x)
Rounds up to a whole number.
ganit.round(x)
Rounds to the nearest whole number.
ganit.random()
A random number from 0 (included) to 1 (not included).
ganit.pow(base, power)
base raised to power.
ganit.sqrt(x)
Square root.
ganit.min(a, b, ...) or ganit.min(list)
The smallest of the numbers (or of a list).
ganit.max(a, b, ...) or ganit.max(list)
The largest of the numbers (or of a list).