Skip to main content
Skip to content

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

Operators

AltFLang operators
OperatorMeaning
+ - * / %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

Output and input built-ins
Built-inWhat it doesExampleJavaScript
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

Types and conversion built-ins
Built-inWhat it doesExampleJavaScript
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

Text built-ins
Built-inWhat it doesExampleJavaScript
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

Text and lists built-ins
Built-inWhat it doesExampleJavaScript
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

Lists built-ins
Built-inWhat it doesExampleJavaScript
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

Map, filter, reduce built-ins
Built-inWhat it doesExampleJavaScript
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

Objects built-ins
Built-inWhat it doesExampleJavaScript
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)

Maths (ganit) built-ins
Built-inWhat it doesExampleJavaScript
ganit.PIThe number π (3.14159…).
ganit.PI * 2
Math.PI
ganit.EEuler'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)