How karya works
karya naam(a, b) { ... } declares a function. Parameters are local variables filled from the call; missing arguments arrive as khali.
AltFLang runs your program from top to bottom, so define a function before the line that calls it. Functions remember the variables around them (closures) and may call themselves (recursion), with a depth limit that turns runaway recursion into an error.
Functions are values: rakho dugna = karya (x) { lautao x * 2; }; stores a nameless function in a variable, and functions can be passed to built-ins such as har and chuno.
Syntax
karya naam(param1, param2) {
// body
lautao result;
}Runnable example
Same idea in JavaScript and Python
function area(l, b) {
return l * b;
}
console.log("Kamra:", area(4, 5), "sq m");def area(l, b):
return l * b
print("Kamra:", area(4, 5), "sq m")Common mistakes
Calling a function before defining it
The declaration has to run before the call. Move the karya block above the line that uses it.
bol(dugna(4));
karya dugna(x) { lautao x * 2; }karya dugna(x) { lautao x * 2; }
bol(dugna(4));Printing instead of returning
A function that only calls bol gives back khali, so its result cannot be used in a calculation. Use lautao to hand the value back.
karya teen_guna(x) { bol(x * 3); }
rakho y = teen_guna(2) + 1;karya teen_guna(x) { lautao x * 3; }
bol(teen_guna(2) + 1);karya: frequently asked questions
How do I return a value from a karya function?
Use lautao followed by the value. lautao ends the function immediately; without it the function returns khali.
Can AltFLang functions be recursive?
Yes. A function may call itself, as long as it has a base case that stops. There is a call-depth limit, so infinite recursion ends with a clear error.