15 keywords · 39 built-ins
AltFLang keywords and built-in functions
AltFLang's reserved words are everyday Hindi words written in English letters. Each one maps to a familiar programming idea — agar is if, jab_tak is while, karya is function. Pick a keyword for its syntax, a runnable example, the JavaScript and Python equivalents and the mistakes beginners make.
Keywords
rakhoVariableslet (declare a variable)rakhocreates a new variable and optionally gives it a starting value. The value can be changed later with a plain=.pakkaVariablesconst (declare a constant)pakkadeclares a name whose value cannot be reassigned. Use it for values that should never change while the program runs.bolOutputprint / console.logbolprints values to the output panel, one line per call. Give it several values separated by commas and it joins them with spaces.chhapOutputprint (alias of bol)chhapprints values exactly likeboldoes. It exists so you can pick the word that feels natural.agarControl flowifagarruns a block of code only when its condition is truthy. Pair it withwarnato handle the other case.warnaControl flowelse / else ifwarnafollows anagarblock and runs when the condition was false.warna agaradds another condition to the chain.jab_takLoopswhile loopjab_takrepeats its block for as long as the condition stays truthy, checking before every round.chaloLoopsfor loopchalois a counting loop with three parts — start, condition and update — separated by semicolons.karyaFunctionsfunctionkaryadefines a reusable function with a name, parameters and a body. Call it by writing its name followed by brackets.lautaoFunctionsreturnlautaoends the current function and hands a value back to the caller.bhangLoopsbreakbhangimmediately ends the innermost loop and continues with the code after it.aageLoopscontinueaageskips the rest of the current loop round and moves straight on to the next one.sahi / galatValuestrue / falsesahi(true) andgalat(false) are AltFLang's two boolean values. Every comparison produces one of them.khaliValuesnull / Nonekhalimeans "no value". It is falsy, and it shows up whenever something was asked for that does not exist.
Operators
| Operator | Meaning |
|---|---|
+ - * / % | 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-in functions
Built-ins are ready-made functions you can call anywhere. They are not reserved words, so you may reuse a name like kul for your own variable — it simply hides the built-in in that scope.
Output and input
| Built-in | What it does | Example | JavaScript |
|---|---|---|---|
bol(...values) | Prints the values on one line, separated by spaces (a statement keyword). | bol("Namaste", 42); // Namaste 42 | console.log(...values) |
chhap(...values) | Alias for bol — identical behaviour. | chhap("Duniya"); // Duniya | console.log(...values) |
pucho(sawal?) | Shows the question and returns the next line of input as text (khali when input runs out). | rakho naam = pucho("Aapka naam?");
bol("Namaste", naam); | prompt(sawal) |
Types and conversion
| Built-in | What it does | Example | JavaScript |
|---|---|---|---|
prakar(x) | Type name: "sankhya", "shabd", "sahi_galat", "suchi", "vastu", "karya" or "khali". | prakar(42); // sankhya
prakar("hi"); // shabd | typeof x |
sankhya(x) | Converts to a number (0 if it is not a valid number). | sankhya("42") + 1; // 43 | Number(x) |
shabd(x) | Converts any value to text, exactly as bol would print it. | shabd(42) + "!"; // "42!" | String(x) |
lambai(x) | Length of a list or text, or the number of keys in an object. | lambai([1, 2, 3]); // 3
lambai("chai"); // 4 | x.length / Object.keys(obj).length |
samay() | Current time in milliseconds since 1 Jan 1970. | rakho shuru = samay(); | Date.now() |
Text
| Built-in | What it does | Example | JavaScript |
|---|---|---|---|
bada(text) | Text in UPPERCASE. | bada("chai"); // "CHAI" | text.toUpperCase() |
chhota(text) | Text in lowercase. | chhota("CHAI"); // "chai" | text.toLowerCase() |
saaf(text) | Removes spaces from both ends of the text. | saaf(" chai "); // "chai" | text.trim() |
kaato(text, sep?) | Splits text into a list at every sep. Without sep it splits into words. | kaato("a,b,c", ","); // ["a", "b", "c"]
kaato("chai aur samosa"); // ["chai", "aur", "samosa"] | text.split(sep) |
milao(list, sep = "") | Joins the list items into one text, with sep between them. | milao(["a", "b", "c"], "-"); // "a-b-c" | list.join(sep) |
badlo(text, purana, naya) | Replaces every purana in the text with naya. | badlo("chai chai", "chai", "coffee"); // "coffee coffee" | text.replaceAll(purana, naya) |
Text and lists
| Built-in | What it does | Example | JavaScript |
|---|---|---|---|
shamil(x, item) | sahi if the list contains item (or the text contains it), else galat. | shamil([1, 2, 3], 2); // sahi
shamil("namaste", "ste"); // sahi | x.includes(item) |
khojo(x, item) | Position (index) of the first item in the list or text, or -1 if missing. | khojo(["a", "b"], "b"); // 1
khojo("chai", "z"); // -1 | x.indexOf(item) |
tukda(x, start, end?) | A piece of the list or text from start up to (not including) end. Negative counts from the end. | tukda([1, 2, 3, 4], 1, 3); // [2, 3]
tukda("namaste", 0, 4); // "nama" | x.slice(start, end) |
ulta(x) | A reversed copy of the list or text (the original is unchanged). | ulta([1, 2, 3]); // [3, 2, 1]
ulta("chai"); // "iahc" | [...x].reverse() |
Lists
| Built-in | What it does | Example | JavaScript |
|---|---|---|---|
jodo(list, item) | Adds item to the end of the list (changes it) and returns the list. | rakho s = [1]; jodo(s, 2); // s is [1, 2] | list.push(item) |
nikalo(list) | Removes and returns the last item of the list (khali if it is empty). | rakho s = [1, 2]; nikalo(s); // 2, s is [1] | list.pop() |
chhanto(list) | A sorted copy of the list: numbers smallest first, anything else alphabetically. | chhanto([3, 1, 2]); // [1, 2, 3] chhanto(["kela", "aam"]); // ["aam", "kela"] | [...list].sort((a, b) => a - b) |
kram(start, end, step = 1) | A list of numbers from start up to (not including) end. kram(n) counts 0 to n-1. | kram(1, 5); // [1, 2, 3, 4] kram(0, 10, 3); // [0, 3, 6, 9] | Array.from({ length: end - start }, (_, i) => start + i) |
kul(list) | The sum of all numbers in the list (0 for an empty list). | kul([10, 20, 30]); // 60 | list.reduce((a, b) => a + b, 0) |
Map, filter, reduce
| Built-in | What it does | Example | JavaScript |
|---|---|---|---|
har(list, fn) | A new list with fn(item, index) applied to every item (map). | har([1, 2, 3], karya (x) { lautao x * 2; }); // [2, 4, 6] | list.map(fn) |
chuno(list, fn) | A new list with only the items for which fn(item, index) is true (filter). | chuno([1, 2, 3, 4], karya (x) { lautao x % 2 == 0; }); // [2, 4] | list.filter(fn) |
ikattha(list, fn, shuru?) | Combines all items into one value: fn(jama, item, index), starting from shuru (reduce). | ikattha([1, 2, 3], karya (jama, x) { lautao jama + x; }, 0); // 6 | list.reduce(fn, shuru) |
Objects
| Built-in | What it does | Example | JavaScript |
|---|---|---|---|
chabiyan(obj) | A list of the object's keys. | chabiyan({ naam: "Asha", umar: 21 }); // ["naam", "umar"] | Object.keys(obj) |
mulya(obj) | A list of the object's values. | mulya({ naam: "Asha", umar: 21 }); // ["Asha", 21] | Object.values(obj) |
Maths (ganit)
| Built-in | What it does | Example | JavaScript |
|---|---|---|---|
ganit.PI | The number π (3.14159…). | ganit.PI * 2 | Math.PI |
ganit.E | Euler's number e (2.71828…). | ganit.E | Math.E |
ganit.abs(x) | Distance from zero (removes the minus sign). | ganit.abs(-7); // 7 | Math.abs(x) |
ganit.floor(x) | Rounds down to a whole number. | ganit.floor(4.9); // 4 | Math.floor(x) |
ganit.ceil(x) | Rounds up to a whole number. | ganit.ceil(4.1); // 5 | Math.ceil(x) |
ganit.round(x) | Rounds to the nearest whole number. | ganit.round(4.5); // 5 | Math.round(x) |
ganit.random() | A random number from 0 (included) to 1 (not included). | ganit.floor(ganit.random() * 6) + 1; // dice: 1-6 | Math.random() |
ganit.pow(base, power) | base raised to power. | ganit.pow(2, 10); // 1024 | Math.pow(base, power) |
ganit.sqrt(x) | Square root. | ganit.sqrt(144); // 12 | Math.sqrt(x) |
ganit.min(a, b, ...) or ganit.min(list) | The smallest of the numbers (or of a list). | ganit.min(4, 2, 8); // 2 | Math.min(a, b) / Math.min(...list) |
ganit.max(a, b, ...) or ganit.max(list) | The largest of the numbers (or of a list). | ganit.max([4, 2, 8]); // 8 | Math.max(a, b) / Math.max(...list) |