Functions & Scope (कार्य व स्कोप)
कार्य <नाव>(पॅरामीटर्स) { परत <मूल्य> }
Functions encapsulate reusable logic. They are declared using कार्य (meaning function/work) and return computed values using परत (return).
1. Defining and Calling Functions
functions.mr
कार्य बेरीज(a, b) {
परत a + b
}
चल निकाल = बेरीज(१०, २०)
छापा(निकाल) // Prints 302. Multi-Parameter Geometric Function
rectangle_function.mr
कार्य क्षेत्र(ल, म) {
परत ल * म
}
कार्य परिमिती(ल, म) {
परत 2 * (ल + म)
}
चल a = क्षेत्र(10, 20)
चल p = परिमिती(10, 20)
छापा(a) // Prints 200
छापा(p) // Prints 603. Scope Isolation
Function parameters and variables defined inside functions are isolated within that function's call frame and do not overwrite outer variables.