docs

Language guide

Syntax & Keywords

Every keyword, operator, and construct in kemlang-py - with examples.

Program structure

Every kemlang-py program must be wrapped in kem bhai and aavjo bhai. Nothing runs outside these fences.

jsk
kem bhai // your code here aavjo bhai
  • kem bhai - Opens the program - literally "hello, brother"
  • aavjo bhai - Closes the program - literally "goodbye, brother"
  • // - Single-line comment - ignored by the interpreter

Variables

Declaration - aa x che val

Declare a new variable with aa (this) and che (is). Every type is inferred automatically.

jsk
kem bhai aa naam che "Sanket" // string aa age che 25 // integer aa pi che 3.14 // float aa flag che bhai chhe // boolean aavjo bhai

Reassignment - x che val

Reassign an existing variable using che without aa.

jsk
kem bhai aa count che 0 count che 1 count che count + 1 bhai bol count // 2 aavjo bhai

Data types

typeexamplesnotes
string"hello" · 'world'single or double quotes
integer42 · -7 · 0whole numbers
float3.14 · -0.5decimal numbers
booleanbhai chhe · bhai nathialso: true / false
none-result of failed input

Output - bhai bol

bhai bol (brother, say) prints any value to stdout. It automatically converts numbers and booleans to strings.

jsk
kem bhai bhai bol "Hello, World!" bhai bol 42 bhai bol 3.14 bhai bol bhai chhe aavjo bhai
output
Hello, World!
42
3.14
true

Input - bapu tame bolo

bapu tame bolo (father, you say) reads a line from stdin and returns it as a string.

jsk
kem bhai bhai bol "What is your name?" aa naam che bapu tame bolo bhai bol "kem cho, " + naam + "!" aavjo bhai

String operations

Use + to concatenate strings. If either side is a string, the other side is automatically cast.

jsk
kem bhai aa first che "Sanket" aa last che "Patel" aa full che first + " " + last bhai bol full // Sanket Patel bhai bol "Age: " + 25 // Age: 25 aavjo bhai

Arithmetic

jsk
kem bhai aa a che 10 aa b che 3 bhai bol a + b // 13 bhai bol a - b // 7 bhai bol a * b // 30 bhai bol a / b // 3.333... bhai bol a % b // 1 (modulo) aavjo bhai

Comparison operators

All comparisons return bhai chhe (true) or bhai nathi (false).

operatormeaning
==equal to
!=not equal to
<less than
>greater than
<=less than or equal
>=greater than or equal
jsk
kem bhai bhai bol 10 == 10 // true bhai bol 10 != 5 // true bhai bol 3 > 7 // false aavjo bhai

Conditionals - jo / nahi to

jo means “if”, nahi to means “otherwise”. Braces are required. There is no else if - nest another jo inside.

jsk
kem bhai aa score che 82 jo score >= 90 { bhai bol "A grade" } nahi to { jo score >= 75 { bhai bol "B grade" } nahi to { bhai bol "C grade" } } aavjo bhai

Loops - farvu / jya sudhi

farvu means “to do”, jya sudhi means “as long as”. The body runs first, then the condition is checked.

jsk
kem bhai aa i che 1 farvu { bhai bol i i che i + 1 } jya sudhi i <= 5 aavjo bhai
output
1
2
3
4
5

Loop control

tame jao - break

Exit the nearest loop immediately.

jsk
kem bhai aa i che 1 farvu { jo i == 4 { tame jao } bhai bol i i che i + 1 } jya sudhi bhai chhe aavjo bhai

aagal vado - continue

Skip the rest of the current iteration and move to the next.

jsk
kem bhai aa i che 0 farvu { i che i + 1 jo i % 2 == 0 { aagal vado } // skip evens bhai bol i } jya sudhi i < 10 aavjo bhai

Full keyword reference

keywordmeaningGujarati
kem bhaiprogram starthello, brother
aavjo bhaiprogram endgoodbye, brother
aa x che valdeclarethis x is val
x che valreassignx is val
bhai bol exprprintbrother, say
bapu tame boloread inputfather, you say
jo cond { }ifif
nahi to { }elseotherwise
farvu { } jya sudhi condwhiledo while
tame jaobreakyou go
aagal vadocontinuemove forward
bhai chhetruebrother is
bhai nathifalsebrother is not