Ganges

Advanced

Let's now explore advance concepts. Here we come across, loops, functions, arrays, hashmaps, hashsets

While Loop

Use the keyword chakra in Ganges for while loops.

Place the condition inside parentheses. The body goes inside curly braces. Statements inside the loop must also end with a semicolon (;).

app/main.ga

1   rama count = 0;

2   chakra (count < 3) {

3     vadha("Spin the chakra");

4     count = count + 1;

5   };

Functions (kriya)

Functions in Ganges are declared using the keyword kriya. You can assign a function to a variable just like any other value — functions are first-class citizens.

The kriya block is an expression, so it can be assigned, passed around, or returned from another function.🧠 expression-based

app/main.ga

1   rama aashirvad = kriya(god) {

2     yadi (god == "vishnu") {

3       vadha("Narayana! Narayana!");

4     } anyatha {

5       vadha("Namah Parvati Patair, Har Har Mahadev!");

6     }

7   };

8   aashirvad("mahadev");

$ Terminal (zsh)

>> Namah Parvati Patair, Har Har Mahadev!

Note

  • Functions are declared using kriya.
  • The body of a function is always a block { }.
  • Functions can be assigned to variables and passed around.
  • Use vadha() to print output.

Arrays

Arrays in Ganges are created using square brackets []. They can store multiple values in order. Access elements using zero-based indexing.

Arrays are expressions, so they can be assigned to variables, passed to functions, or returned.expression-based

app/array.ga

1   rama gods = ["vishnu", "shiva", "brahma"];

2   vadha(gods[0]);

3   vadha(gods[1]);

$ Terminal (zsh)

>> vishnu

>> shiva

Notes

  • Arrays are defined using [].
  • Indexing starts from 0.
  • Arrays can be nested or passed to functions.
  • Use gods.length (if supported) to get length. (Coming soon)

Hashmaps

In Ganges, hashmaps (or dictionaries) store key-value pairs. Keys are strings, and access is done via bracket notation.

Useful for fast lookups and grouping related values.

app/main.ga

1   rama gods = {

"preserver": "vishnu",

"destroyer": "shiva",

   };

5   vadha(gods["preserver"]);

6   vadha(gods["destroyer"]);

$ Terminal (zsh)

>> vishnu

>> shiva

Notes

  • Hashmaps are declared with {} and key-value pairs.
  • Keys must be strings. Values can be any expression.
  • Use bracket notation to access: gods["preserver"]

Hashsets

In Ganges, hashsets store **unique** values — duplicates are ignored. They are useful for fast membership checks and uniqueness guarantees.

Use hashset(...) to declare one, and check membership using.contains(value).

app/main.ga

1   rama gods = hashset("vishnu", "shiva", "brahma");

3   vadha(gods.contains("shiva"));

4   vadha(gods.contains("kali"));

$ Terminal (zsh)

>> satya

>> asatya

Notes

  • hashset(...) auto-removes duplicates on insert.
  • .contains(value) returns true or false.
  • Sets are unordered and fast for lookup.

Hashset Operations

Ganges Hashsets support key operations like membership checks, insertion, and deletion using the methods below.

app/main.ga

1   rama gods = hashset("shiva");

3   vadha(gods.has("shiva"));

4   gods.add("vishnu");

5   vadha(gods.has("vishnu"));

6   gods.remove("shiva");

7   vadha(gods.has("shiva"));

$ Terminal (zsh)

>> satya

>> satya

>> asatya

has()

Checks if a value exists in the set. Returns true or false.

add()

Adds a new value to the set. If it already exists, no change occurs.

remove()

Deletes a value from the set if present.