DocumentationCore ConceptsFunctions
Functions
Learn how to define reusable blocks, pass arguments, and call functions to organize and simplify your Spark programs.
Function Declaration
A function is declared using the func keyword, followed by the function name and optional parameters.
# function declaration
func showWelcomeMessage
print "Welcome to Spark!"
endFunction Parameters
Functions can accept parameters that act as variables inside the function body.
# function declaration
func greetUser name,age
print "Hello", name, "Your age is", age
end
# function call
fn greetUser "john" 22Function Call
Functions are executed using the fn keyword, followed by the function name and arguments.
# function calls
fn greetUser "soham" 22
fn showWelcomeMessageComplete Example
func showWelcomeMessage
print "Welcome to Spark!"
end
func greetUser name,age
print "Hello", name, "Your age is", age
end
fn greetUser "John" 22
fn showWelcomeMessage