A Parameter is a variable declaration in a function definition that specifies what values the function can receive when called. Each parameter must declare its Data Type and name, creating a local variable that exists only within the function's scope.
Parameters are declared inside the Group delimiters following a function name. Each parameter consists of:
A function with one parameter receives a single value when called.
FUNCTION square ( INT n )
NEW INT result = n * n
RETURN result
END FUNCTION
NEW INT value = square ( 5 )
PRINTLN value // Displays "25"FUNCTION greet ( STR name )
PRINTLN "Hello, " .. name .. "!"
END FUNCTION
greet ( "Alice" )
// Displays "Hello, Alice!"FUNCTION double ( FLOAT value )
NEW FLOAT result = value * 2.0
RETURN result
END FUNCTION
NEW FLOAT doubled = double ( 3.5 )
PRINTLN doubled // Displays "7.0"FUNCTION checkStatus ( BOOL isActive )
IF isActive == TRUE
PRINTLN "Status: Active"
ELSE
PRINTLN "Status: Inactive"
END IF
END FUNCTION
checkStatus ( TRUE )
// Displays "Status: Active"When a function needs multiple values, parameters are separated by the Divider delimiter (comma). Each parameter must have its own data type declaration.
FUNCTION add ( INT a , INT b )
NEW INT sum = a + b
RETURN sum
END FUNCTION
NEW INT result = add ( 5 , 3 )
PRINTLN result // Displays "8"FUNCTION calculateAverage ( FLOAT a , FLOAT b , FLOAT c )
NEW FLOAT sum = a + b + c
NEW FLOAT avg = sum / 3.0
RETURN avg
END FUNCTION
NEW FLOAT average = calculateAverage ( 10.0 , 20.0 , 30.0 )
PRINTLN average // Displays "20.0"FUNCTION displayInfo ( STR name , INT age , FLOAT height , BOOL isStudent )
PRINTLN "Name: " .. name
PRINTLN "Age: " .. age
PRINTLN "Height: " .. height
PRINTLN "Student: " .. isStudent
END FUNCTION
displayInfo ( "Bob" , 25 , 5.9 , TRUE )FUNCTION createRecord ( STR firstName , STR lastName , INT age , FLOAT salary , BOOL active )
NEW STR fullName = firstName .. " " .. lastName
PRINTLN "Employee: " .. fullName
PRINTLN "Age: " .. age
PRINTLN "Salary: $" .. salary
PRINTLN "Active: " .. active
END FUNCTION
createRecord ( "John" , "Doe" , 30 , 50000.0 , TRUE )Functions can be defined with no parameters, indicated by empty Group delimiters.
FUNCTION sayHello ( )
PRINTLN "Hello, World!"
END FUNCTION
sayHello ( )
// Displays "Hello, World!"FUNCTION getDefaultValue ( )
RETURN 42
END FUNCTION
NEW INT value = getDefaultValue ( )
PRINTLN value // Displays "42"Parameters are the variable declarations in the function definition. Arguments are the actual values passed when calling the function.
// Parameters: INT x and INT y (defined in function)
FUNCTION multiply ( INT x , INT y )
RETURN x * y
END FUNCTION
// Arguments: 6 and 7 (passed to function)
NEW INT result = multiply ( 6 , 7 )
PRINTLN result // Displays "42"Parameters are local variables that exist only within the function. They cannot be accessed outside the function.
FUNCTION calculate ( INT value )
NEW INT doubled = value * 2
RETURN doubled
END FUNCTION
NEW INT result = calculate ( 10 )
PRINTLN result // Displays "20"
// PRINTLN value // Runtime error! value doesn't exist hereNEW INT original = 5
FUNCTION modifyValue ( INT num )
SET num = num + 10
PRINTLN "Inside function: " .. num
RETURN num
END FUNCTION
NEW INT modified = modifyValue ( original )
PRINTLN "Original: " .. original // Displays "Original: 5"
PRINTLN "Modified: " .. modified // Displays "Modified: 15"Arguments are matched to parameters by position. The first argument is assigned to the first parameter, the second to the second, and so on.
FUNCTION divide ( INT numerator , INT denominator )
NEW INT result = numerator / denominator
RETURN result
END FUNCTION
NEW INT answer1 = divide ( 10 , 2 )
PRINTLN answer1 // Displays "5" (10 / 2)
NEW INT answer2 = divide ( 2 , 10 )
PRINTLN answer2 // Displays "0" (2 / 10 = 0 in integer division)FUNCTION calculateDiscount ( FLOAT originalPrice , FLOAT discountPercent )
NEW FLOAT discount = originalPrice * ( discountPercent / 100.0 )
NEW FLOAT finalPrice = originalPrice - discount
RETURN finalPrice
END FUNCTION
NEW FLOAT price = calculateDiscount ( 100.0 , 20.0 )
PRINTLN price // Displays "80.0"Parameter names follow the same rules as variable names: they can contain letters (both uppercase and lowercase) and are case-sensitive.
FUNCTION example ( INT value , INT Value , INT VALUE )
NEW INT sum = value + Value + VALUE
RETURN sum
END FUNCTION
NEW INT total = example ( 1 , 2 , 3 )
PRINTLN total // Displays "6"FUNCTION checkEligibility ( BOOL isAdult , BOOL hasLicense )
IF isAdult && hasLicense
RETURN TRUE
ELSE
RETURN FALSE
END IF
END FUNCTION
NEW BOOL canDrive = checkEligibility ( TRUE , TRUE )
PRINTLN canDrive // Displays "TRUE"FUNCTION isInRange ( INT value , INT min , INT max )
NEW BOOL inRange = ( value >= min ) && ( value <= max )
RETURN inRange
END FUNCTION
IF isInRange ( 50 , 1 , 100 )
PRINTLN "In range"
END IF
// Displays "In range"FUNCTION calculateArea ( FLOAT width , FLOAT height )
NEW FLOAT area = width * height
RETURN area
END FUNCTION
NEW FLOAT roomArea = calculateArea ( 10.5 , 8.0 )
PRINTLN "Area: " .. roomArea // Displays "Area: 84.0"FUNCTION getFullName ( STR firstName , STR lastName )
NEW STR fullName = firstName .. " " .. lastName
RETURN fullName
END FUNCTION
NEW STR name = getFullName ( "John" , "Doe" )
PRINTLN name // Displays "John Doe"FUNCTION getGrade ( INT score )
NEW STR grade = ""
IF score >= 90
SET grade = "A"
ELIF score >= 80
SET grade = "B"
ELIF score >= 70
SET grade = "C"
ELIF score >= 60
SET grade = "D"
ELSE
SET grade = "F"
END IF
RETURN grade
END FUNCTION
NEW STR letterGrade = getGrade ( 85 )
PRINTLN letterGrade // Displays "B"FUNCTION factorial ( INT n )
NEW INT result = 1
NEW INT i = 1
WHILE i <= n
SET result = result * i
SET i = i + 1
END WHILE
RETURN result
END FUNCTION
NEW INT fact5 = factorial ( 5 )
PRINTLN "5! = " .. fact5 // Displays "5! = 120"FUNCTION celsiusToFahrenheit ( FLOAT celsius )
NEW FLOAT fahrenheit = ( celsius * 9.0 / 5.0 ) + 32.0
RETURN fahrenheit
END FUNCTION
NEW FLOAT tempF = celsiusToFahrenheit ( 25.0 )
PRINTLN tempF // Displays "77.0"FUNCTION calculateTax ( FLOAT amount , FLOAT rate )
NEW FLOAT tax = amount * rate
RETURN tax
END FUNCTION
FUNCTION getTotalWithTax ( FLOAT amount , FLOAT taxRate )
NEW FLOAT tax = calculateTax ( amount , taxRate )
NEW FLOAT total = amount + tax
RETURN total
END FUNCTION
NEW FLOAT total = getTotalWithTax ( 100.0 , 0.08 )
PRINTLN "Total: $" .. total // Displays "Total: $108.0"FUNCTION formatMessage ( STR prefix , STR content , STR suffix )
NEW STR message = prefix .. " " .. content .. " " .. suffix
RETURN message
END FUNCTION
NEW STR output = formatMessage ( "[INFO]" , "Process completed" , "successfully" )
PRINTLN output // Displays "[INFO] Process completed successfully"FUNCTION add ( a , b )
RETURN a + b
END FUNCTION
// Syntax error! Parameters missing data types
// Correct:
FUNCTION add ( INT a , INT b )
RETURN a + b
END FUNCTIONFUNCTION calculate ( INT value , INT value )
RETURN value + value
END FUNCTION
// Runtime error! Duplicate parameter name
// Correct:
FUNCTION calculate ( INT value1 , INT value2 )
RETURN value1 + value2
END FUNCTIONFUNCTION multiply ( INT x , INT y )
RETURN x * y
END FUNCTION
NEW INT result = multiply ( 5 )
// Runtime error! Missing second argument
// Correct:
NEW INT result = multiply ( 5 , 3 )FUNCTION double ( INT n )
RETURN n * 2
END FUNCTION
NEW INT result = double ( 5.5 )
// Type error! Expected INT, got FLOAT
// Correct:
NEW INT result = double ( 5 )FUNCTION add ( INT a INT b )
RETURN a + b
END FUNCTION
// Syntax error! Missing comma between parameters
// Correct:
FUNCTION add ( INT a , INT b )
RETURN a + b
END FUNCTION