Skip to main content
Skip to content

AltFLang documentation

The complete language reference: keywords, values, control flow, functions and the built-in library. Every code block runs right here — press Run, or open it in the playground to edit.

Getting Started

Overview of AltFLang syntax, execution model, and core concepts.

What is AltFLang?

AltFLang is a modern, high-performance conversational programming language designed with an intuitive desi-style syntax. It runs entirely inside your browser with a custom-built Lexer, Parser, AST, and Interpreter — zero external dependencies or server compilation required.

Key Syntax Rules

  • Statements can end with a semicolon ; or a new line — the semicolon is optional.
  • Single-line comments start with // or #.
  • Multi-line comments are enclosed in /* ... */.
  • Blocks are enclosed with curly braces { ... }.
  • Output is printed using bol(...) or chhap(...).

Variables & Constants

Declaring mutable variables with rakho and constants with pakka.

Variable Declaration (rakho)

Use rakho to declare mutable variables:

altflang
rakho aam = 10;
aam = 20; // Re-assignment is allowed
bol("Aam ki count:", aam);

Constant Declaration (pakka)

Use pakka to declare constants that cannot be reassigned:

altflang
pakka PI = 3.14159;
// Reassigning PI will throw a Runtime Error!

Updating a value (+=, -=, *=, /=)

Compound assignment is a shortcut for "use the old value and store the result":

altflang
rakho score = 10;
score += 5;   // same as score = score + 5
score *= 2;   // 30
bol("Score:", score);

It also works on list items and object properties: suchi[0] += 1;, khiladi.ank -= 2;.

Your names win over built-ins

Built-in helpers live in an outer scope, so you may reuse their names for your own variables. After rakho kul = 0; the name kul is your number, not the built-in.

altflang
rakho kul = 0;
kul += 7;
bol("Mera kul:", kul);

Try it

altflang
rakho aam = 10;
aam = 20;
bol("Aam ki count:", aam);

pakka PI = 3.14159;
bol("PI value:", PI);

Data Types

Numbers, Strings, Booleans, Null, Lists (Arrays), and Objects.

AltFLang supports standard dynamic primitives and compound data structures:

TypeAltFLang Literal / ValueDescription
Number10, 3.14, -5Integers and floating-point numbers
String"Namaste", 'Duniya'Text literals with escape sequences
Booleansahi (true), galat (false)Truthy/falsy boolean values
NullkhaliRepresents empty or non-existent value
Array[1, 2, "aam"]Ordered zero-indexed lists
Object{ naam: "AltF", aayu: 1 }Key-value mapping pairs
altflang
rakho Suchi = [10, 20, 30];
rakho Vastu = { chabi: "Moolya" };
bol("Array zero index:", Suchi[0]);
bol("Object property:", Vastu.chabi);

Operators

Arithmetic, comparison, and logical operators.

Arithmetic Operators

+ (addition / string concatenation), - (subtraction), * (multiplication), / (division), % (modulo).

Comparison Operators

== (equal), != (not equal), < (less than), > (greater than), <= (less than or equal), >= (greater than or equal).

Logical Operators

&& (AND), || (OR), ! (NOT).

Assignment Operators

= (assign), and the shortcuts +=, -=, *=, /=. There is no ++ or -- — write i += 1.

altflang
rakho a = 15;
rakho b = 4;
bol("Modulo:", a % b); // 3
bol("Logical AND:", (a > 10) && (b < 5)); // sahi

Conditionals (agar / warna)

Decision making using agar, warna agar, and warna.

Conditionals evaluate expressions and execute matching blocks:

altflang
rakho ank = 85;

agar (ank >= 90) {
  bol("A+ Grade!");
} warna agar (ank >= 75) {
  bol("First Division!");
} warna {
  bol("Pass");
}

Loops (jab_tak / chalo)

Iteration loops, break (bhang), and continue (aage).

While Loop (jab_tak)

altflang
rakho ginti = 0;
jab_tak (ginti < 5) {
  bol("Kram:", ginti);
  ginti += 1;
}

For Loop (chalo)

altflang
chalo (rakho i = 0; i < 3; i += 1) {
  agar (i == 1) {
    aage; // skip 1
  }
  bol("Loop index:", i);
}

Skip and Stop (aage / bhang)

aage skips to the next iteration; bhang leaves the loop entirely.

altflang
chalo (rakho i = 0; i < 5; i += 1) {
  agar (i == 3) {
    bhang; // stop the loop at 3
  }
  bol("Chal raha hai:", i);
}
// prints 0, 1, 2

bhang and aage only work inside a loop, and lautao only inside a karya — anywhere else is a syntax error.

Loops nest freely, and both keywords apply to the innermost loop:

altflang
chalo (rakho i = 0; i < 2; i += 1) {
  chalo (rakho j = 0; j < 2; j += 1) {
    bol(i, j);
  }
}

Functions (karya / lautao)

Creating modular functions and returning values.

Functions are declared with karya and return with lautao:

altflang
karya guna_karo(x, y) {
  lautao x * y;
}

rakho uttar = guna_karo(6, 7);
bol("6 * 7 =", uttar);

Recursion

A function can call itself. lautao exits immediately, so the base case guards the recursion:

altflang
karya factorial(n) {
  agar (n <= 1) {
    lautao 1;
  }
  lautao n * factorial(n - 1);
}

bol("5! =", factorial(5)); // 120

First-class functions

Functions are values: pass them as arguments, return them, store them in variables. A returned function keeps access to the scope it was created in (a closure):

altflang
karya ginti_banao() {
  rakho ginti = 0;
  karya badhao() {
    ginti = ginti + 1;
    lautao ginti;
  }
  lautao badhao;
}

rakho counter = ginti_banao();
counter();
bol("Counter:", counter()); // 2

Function expressions

karya also works as a value — leave out the name (or keep one, so the function can call itself). Store it in a variable or pass it straight to a built-in:

altflang
rakho dugna = karya (x) {
  lautao x * 2;
};
bol(dugna(21)); // 42

bol(har([1, 2, 3], dugna)); // [2, 4, 6]
bol(chuno([5, 12, 8, 20], karya (x) { lautao x > 10; })); // [12, 20]

Built-in Functions & Library

Standard library helpers for printing, text, lists, objects, input and math.

Built-ins are always available. You can still use any of their names for your own variables (rakho kul = 0; is fine) — your name simply wins from then on.

Output

  • bol(...values): Prints the values on one line, separated by spaces (a statement keyword). Example: bol("Namaste", 42); // Namaste 42
  • chhap(...values): Alias for bol — identical behaviour. Example: chhap("Duniya"); // Duniya

Core helpers

  • lambai(x): Length of a list or text, or the number of keys in an object. Example: lambai([1, 2, 3]); // 3
  • prakar(x): Type name: "sankhya", "shabd", "sahi_galat", "suchi", "vastu", "karya" or "khali". Example: prakar(42); // sankhya
  • jodo(list, item): Adds item to the end of the list (changes it) and returns the list. Example: rakho s = [1]; jodo(s, 2); // s is [1, 2]
  • nikalo(list): Removes and returns the last item of the list (khali if it is empty). Example: rakho s = [1, 2]; nikalo(s); // 2, s is [1]
  • sankhya(x): Converts to a number (0 if it is not a valid number). Example: sankhya("42") + 1; // 43
  • shabd(x): Converts any value to text, exactly as bol would print it. Example: shabd(42) + "!"; // "42!"
  • samay(): Current time in milliseconds since 1 Jan 1970. Example: rakho shuru = samay();

Text (shabd)

  • bada(text): Text in UPPERCASE. Example: bada("chai"); // "CHAI"
  • chhota(text): Text in lowercase. Example: chhota("CHAI"); // "chai"
  • saaf(text): Removes spaces from both ends of the text. Example: saaf(" chai "); // "chai"
  • kaato(text, sep?): Splits text into a list at every sep. Without sep it splits into words. Example: kaato("a,b,c", ","); // ["a", "b", "c"]
  • milao(list, sep = ""): Joins the list items into one text, with sep between them. Example: milao(["a", "b", "c"], "-"); // "a-b-c"
  • badlo(text, purana, naya): Replaces every purana in the text with naya. Example: badlo("chai chai", "chai", "coffee"); // "coffee coffee"

Text and lists

  • shamil(x, item): sahi if the list contains item (or the text contains it), else galat. Example: shamil([1, 2, 3], 2); // sahi
  • khojo(x, item): Position (index) of the first item in the list or text, or -1 if missing. Example: khojo(["a", "b"], "b"); // 1
  • tukda(x, start, end?): A piece of the list or text from start up to (not including) end. Negative counts from the end. Example: tukda([1, 2, 3, 4], 1, 3); // [2, 3]
  • ulta(x): A reversed copy of the list or text (the original is unchanged). Example: ulta([1, 2, 3]); // [3, 2, 1]

Lists (suchi)

  • chhanto(list): A sorted copy of the list: numbers smallest first, anything else alphabetically. Example: chhanto([3, 1, 2]); // [1, 2, 3]
  • kram(start, end, step = 1): A list of numbers from start up to (not including) end. kram(n) counts 0 to n-1. Example: kram(1, 5); // [1, 2, 3, 4]
  • har(list, fn): A new list with fn(item, index) applied to every item (map). Example: har([1, 2, 3], karya (x) { lautao x * 2; }); // [2, 4, 6]
  • chuno(list, fn): A new list with only the items for which fn(item, index) is true (filter). Example: chuno([1, 2, 3, 4], karya (x) { lautao x % 2 == 0; }); // [2, 4]
  • ikattha(list, fn, shuru?): Combines all items into one value: fn(jama, item, index), starting from shuru (reduce). Example: ikattha([1, 2, 3], karya (jama, x) { lautao jama + x; }, 0); // 6
  • kul(list): The sum of all numbers in the list (0 for an empty list). Example: kul([10, 20, 30]); // 60

Objects (vastu)

  • chabiyan(obj): A list of the object's keys. Example: chabiyan({ naam: "Asha", umar: 21 }); // ["naam", "umar"]
  • mulya(obj): A list of the object's values. Example: mulya({ naam: "Asha", umar: 21 }); // ["Asha", 21]

Input

  • pucho(sawal?): Shows the question and returns the next line of input as text (khali when input runs out). Example: rakho naam = pucho("Aapka naam?");

Maths (ganit)

  • ganit.<naam>: Maths helpers: PI, E, abs, floor, ceil, round, random, pow, sqrt, min, max.
  • 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).

Passing functions to built-ins

har, chuno and ikattha take a function — a karya name or a karya (x) { ... } expression. It receives the item and its index:

altflang
rakho daam = [120, 45, 300, 80];
rakho mehnge = chuno(daam, karya (d) { lautao d > 100; });
rakho total = ikattha(daam, karya (jama, d) { lautao jama + d; }, 0);
bol("Mehnge:", mehnge);              // [120, 300]
bol("Total:", total, "=", kul(daam)); // 545 = 545
bol(milao(har(kram(1, 4), shabd), " + ")); // 1 + 2 + 3

Reading input (pucho)

pucho("sawal") shows the question and returns the next line of input as text. In the playground, type the input lines (one answer per line) before you press Run. When the input runs out, pucho returns khali. Use sankhya(...) to turn an answer into a number:

altflang
rakho naam = pucho("Aapka naam?");
agar (naam == khali) {
  naam = "Dost";
}
bol("Namaste,", naam);
altflang
bol("Math Random:", ganit.random());
bol("Square Root of 144:", ganit.sqrt(144));
bol(bada("chai"), ulta([1, 2, 3]), chhanto([3, 1, 2]));

Working with Lists & Objects

Reading, mutating, and nesting suchi (arrays) and vastu (objects).

Arrays are zero-indexed and mutable in place:

altflang
rakho suchi = [1, 2, 3];
suchi[0] = 99;          // assign by index
jodo(suchi, 4);         // push
rakho aakhri = nikalo(suchi); // pop, returns the removed item
bol(suchi, aakhri, lambai(suchi));

Objects support both dot and bracket access, and nest freely:

altflang
rakho vastu = { naam: "AltF", andar: { saal: 2026 } };
bol(vastu.naam);            // dot
bol(vastu["naam"]);         // bracket
bol(vastu.andar.saal);      // nested

lambai works on all three: arrays, strings, and object keys. chabiyan(vastu) and mulya(vastu) give an object's keys and values as lists.

Assigning past the end of a list is an error — use jodo to add items at the end. Reading a missing index or property gives khali.

Try it

altflang
rakho log = [{ naam: "Asha" }, { naam: "Bilal" }];
jodo(log, { naam: "Chetan" });

chalo (rakho i = 0; i < lambai(log); i += 1) {
  bol(i, "->", log[i].naam);
}

Truthiness & Error Messages

Which values count as false, and how the interpreter reports failures.

What counts as false

agar treats these as false — everything else is true:

ValueTruthiness
galatfalse
khalifalse
0false
"" (empty string)false
altflang
agar (0) { bol("nahi chalega"); } warna { bol("0 is falsy"); }
agar ("") { bol("nahi chalega"); } warna { bol("empty string is falsy"); }

Error messages

Errors carry the exact line and column, and stop execution at that point:

altflang
pakka PI = 3.14159;
PI = 3;

Running that stops with:

altflang
[Line 2, Column 4] Runtime Error: Cannot reassign constant variable 'PI'

The playground highlights the offending line in the editor and prints the same message in the output console, so you can jump straight to it. Most errors also come with a short Hinglish tip — for example, writing if instead of agar suggests the AltFLang keyword, and an endless loop reminds you to update the loop variable.

About this page

AltFLang: a Hinglish programming language on AltFTool

AltFLang is a small programming language on AltFTool whose keywords are everyday Hindi and Hinglish words: rakho for a variable, agar for if, karya for a function and bol to print. It is built for learning to code in Hindi, and programs run in your browser.

The section has twelve step-by-step lessons, example programs shown with their output, a keyword reference, documentation, a cheat sheet and a playground editor where you can write code, pass it input and see the JavaScript version of the same program.

People also search for

  • coding in hindi
  • hinglish programming language
  • learn programming in hindi
  • hindi coding language
  • programming for beginners hindi
  • online code runner
  • hindi programming language online
  • learn coding in hinglish