The Divider token is used to separate multiple parameters in function definitions and multiple arguments in function calls. It acts as a separator that clearly distinguishes between different values being passed to or defined in a function.
The short syntax structure uses the , symbol:
FUNCTION NAME ( PARAMETER , PARAMETER , PARAMETER )
STATEMENTS
END FUNCTIONThe long syntax structure uses the word DIVIDER:
FUNCTION NAME GROUP PARAMETER DIVIDER PARAMETER DIVIDER PARAMETER END GROUP
STATEMENTS
END FUNCTIONThe Divider delimiter separates:
When defining a Function with multiple parameters, the Divider separates each parameter declaration.
FUNCTION add ( INT a , INT b )
NEW INT sum = a + b
RETURN sum
END FUNCTIONFUNCTION calculateTotal ( FLOAT price , FLOAT tax , FLOAT discount )
NEW FLOAT total = ( price + tax ) - discount
RETURN total
END FUNCTIONFUNCTION displayInfo ( STR name , INT age , BOOL isStudent )
PRINTLN "Name: " .. name
PRINTLN "Age: " .. age
PRINTLN "Student: " .. isStudent
END FUNCTIONFUNCTION createLabel ( STR prefix , INT value , STR unit , STR suffix )
NEW STR label = prefix .. value .. unit .. suffix
RETURN label
END FUNCTIONWhen calling a function with multiple arguments, the Divider separates each argument value.
FUNCTION multiply ( INT x , INT y )
RETURN x * y
END FUNCTION
NEW INT result = multiply ( 6 , 7 )
PRINTLN result // Displays "42"FUNCTION getAverage ( 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 = getAverage ( 10.0 , 20.0 , 30.0 )
PRINTLN average // Displays "20.0"FUNCTION greet ( STR greeting , STR name )
PRINTLN greeting .. ", " .. name .. "!"
END FUNCTION
NEW STR userName = "Alice"
greet ( "Hello" , userName )
// Displays "Hello, Alice!"FUNCTION calculate ( INT a , INT b , INT c )
NEW INT result = a + b + c
RETURN result
END FUNCTION
NEW INT x = 5
NEW INT y = 3
NEW INT total = calculate ( x , y , x + y )
PRINTLN total // Displays "16"
// Arguments: 5, 3, 8According to ProtoLang's token spacing rules, there must be exactly one space before and after the Divider delimiter.
FUNCTION sum ( INT a , INT b , INT c )
RETURN a + b + c
END FUNCTION
// Correct: One space before and after each commaFunctions can have many parameters, each separated by a Divider.
FUNCTION createRecord ( STR name , INT age , FLOAT height , BOOL active , STR status )
PRINTLN "Name: " .. name
PRINTLN "Age: " .. age
PRINTLN "Height: " .. height
PRINTLN "Active: " .. active
PRINTLN "Status: " .. status
END FUNCTION
createRecord ( "Bob" , 30 , 5.9 , TRUE , "Enrolled" )FUNCTION calculateRectangleArea ( FLOAT length , FLOAT width )
NEW FLOAT area = length * width
RETURN area
END FUNCTION
NEW FLOAT area = calculateRectangleArea ( 10.5 , 8.0 )
PRINTLN "Area: " .. area // Displays "Area: 84.0"FUNCTION getFullName ( STR firstName , STR middleName , STR lastName )
NEW STR fullName = firstName .. " " .. middleName .. " " .. lastName
RETURN fullName
END FUNCTION
NEW STR name = getFullName ( "John" , "Robert" , "Doe" )
PRINTLN name // Displays "John Robert Doe"FUNCTION convertTemperature ( FLOAT value , STR fromUnit , STR toUnit )
NEW FLOAT result = 0.0
IF fromUnit == "C"
IF toUnit == "F"
SET result = ( value * 9.0 / 5.0 ) + 32.0
END IF
END IF
RETURN result
END FUNCTION
NEW FLOAT fahrenheit = convertTemperature ( 25.0 , "C" , "F" )
PRINTLN fahrenheit // Displays "77.0"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 "Value is in range"
ELSE
PRINTLN "Value is out of range"
END IF
// Displays "Value is in range"FUNCTION applyDiscount ( FLOAT price , FLOAT discountPercent , BOOL isMember )
NEW FLOAT discount = 0.0
IF isMember == TRUE
SET discount = price * ( discountPercent / 100.0 )
END IF
NEW FLOAT finalPrice = price - discount
RETURN finalPrice
END FUNCTION
NEW FLOAT price = applyDiscount ( 100.0 , 20.0 , TRUE )
PRINTLN "Final price: $" .. price // Displays "Final price: $80.0"When function calls are nested, Dividers separate arguments at each level.
FUNCTION add ( INT a , INT b )
RETURN a + b
END FUNCTION
FUNCTION multiply ( INT x , INT y )
RETURN x * y
END FUNCTION
NEW INT result = multiply ( add ( 2 , 3 ) , add ( 4 , 5 ) )
PRINTLN result // Displays "45"
// Inner calls: add(2, 3) = 5, add(4, 5) = 9
// Outer call: multiply(5, 9) = 45FUNCTION max ( INT a , INT b )
IF a > b
RETURN a
ELSE
RETURN b
END IF
END FUNCTION
FUNCTION min ( INT a , INT b )
IF a < b
RETURN a
ELSE
RETURN b
END IF
END FUNCTION
NEW INT result = max ( min ( 10 , 5 ) , min ( 8 , 12 ) )
PRINTLN result // Displays "8"
// min(10, 5) = 5, min(8, 12) = 8
// max(5, 8) = 8FUNCTION 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 FUNCTIONFUNCTION multiply ( INT x , INT y )
RETURN x * y
END FUNCTION
NEW INT result = multiply ( 5 10 )
// Syntax error! Missing comma between arguments
// Correct:
NEW INT result = multiply ( 5 , 10 )FUNCTION add ( INT a , INT b , )
RETURN a + b
END FUNCTION
// Syntax error! Extra comma after last parameter
// Correct:
FUNCTION add ( INT a , INT b )
RETURN a + b
END FUNCTIONFUNCTION calculate ( , INT a , INT b )
RETURN a + b
END FUNCTION
// Syntax error! Comma before first parameter
// Correct:
FUNCTION calculate ( INT a , INT b )
RETURN a + b
END FUNCTIONFUNCTION add ( INT a , INT b , INT c )
RETURN a + b + c
END FUNCTION
NEW INT result = add ( 5 , 10 )
// Runtime error! Missing third argument
// Correct:
NEW INT result = add ( 5 , 10 , 15 )FUNCTION add ( INT a,INT b )
RETURN a + b
END FUNCTION
// Syntax error! Missing spaces around comma
// Correct:
FUNCTION add ( INT a , INT b )
RETURN a + b
END FUNCTIONFUNCTION divide ( INT numerator , INT denominator )
RETURN numerator / denominator
END FUNCTION
NEW INT result = divide ( 2 , 10 )
PRINTLN result // Displays "0" (integer division: 2/10 = 0)
// Correct order for 10/2:
NEW INT correct = divide ( 10 , 2 )
PRINTLN correct // Displays "5"