ProtoLang.net

Reference: Divider

☰ Hide Sidebar
TOKEN DIVIDER
ALIAS ,

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.

Syntax

The short syntax structure uses the , symbol:

FUNCTION NAME ( PARAMETER , PARAMETER , PARAMETER )
    STATEMENTS
END FUNCTION

The long syntax structure uses the word DIVIDER:

FUNCTION NAME GROUP PARAMETER DIVIDER PARAMETER DIVIDER PARAMETER END GROUP
    STATEMENTS
END FUNCTION

Purpose

The Divider delimiter separates:

  • Parameters in function definitions
  • Arguments in function calls

Divider in Function Definitions

When defining a Function with multiple parameters, the Divider separates each parameter declaration.

Example: Two Parameters

FUNCTION add ( INT a , INT b )
    NEW INT sum = a + b
    RETURN sum
END FUNCTION

Example: Three Parameters

FUNCTION calculateTotal ( FLOAT price , FLOAT tax , FLOAT discount )
    NEW FLOAT total = ( price + tax ) - discount
    RETURN total
END FUNCTION

Example: Multiple Parameter Types

FUNCTION displayInfo ( STR name , INT age , BOOL isStudent )
    PRINTLN "Name: " .. name
    PRINTLN "Age: " .. age
    PRINTLN "Student: " .. isStudent
END FUNCTION

Example: Four Parameters

FUNCTION createLabel ( STR prefix , INT value , STR unit , STR suffix )
    NEW STR label = prefix .. value .. unit .. suffix
    RETURN label
END FUNCTION

Divider in Function Calls

When calling a function with multiple arguments, the Divider separates each argument value.

Example: Calling with Two Arguments

FUNCTION multiply ( INT x , INT y )
    RETURN x * y
END FUNCTION

NEW INT result = multiply ( 6 , 7 )
PRINTLN result // Displays "42"

Example: Calling with Three Arguments

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"

Example: Mixing Literal and Variable Arguments

FUNCTION greet ( STR greeting , STR name )
    PRINTLN greeting .. ", " .. name .. "!"
END FUNCTION

NEW STR userName = "Alice"
greet ( "Hello" , userName )
// Displays "Hello, Alice!"

Example: Using Expressions as Arguments

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, 8

Divider Spacing

According to ProtoLang's token spacing rules, there must be exactly one space before and after the Divider delimiter.

Example: Correct Spacing

FUNCTION sum ( INT a , INT b , INT c )
    RETURN a + b + c
END FUNCTION
// Correct: One space before and after each comma

Multiple Dividers

Functions can have many parameters, each separated by a Divider.

Example: Five Parameters

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" )

Practical Applications

Example: Rectangle Area Calculator

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"

Example: Full Name Constructor

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"

Example: Temperature Converter

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"

Example: Range Validator

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"

Example: Discount Calculator

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"

Nested Function Calls

When function calls are nested, Dividers separate arguments at each level.

Example: Nested Calls with Multiple Arguments

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) = 45

Example: Complex Nested Expression

FUNCTION 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) = 8

Important Notes

  • The Divider , separates parameters in function definitions.
  • The Divider , separates arguments in function calls.
  • Exactly one space is required before and after each Divider.
  • The number of arguments must match the number of parameters.
  • Arguments must match the data types of their corresponding parameters.
  • Functions with no parameters do not use Dividers.
  • The order of arguments matters - they are matched to parameters by position.

Common Errors

Error: Missing Divider Between Parameters

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

Error: Missing Divider Between Arguments

FUNCTION 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 )

Error: Extra Divider

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 FUNCTION

Error: Divider Before First Parameter

FUNCTION 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 FUNCTION

Error: Wrong Number of Arguments

FUNCTION 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 )

Error: Incorrect Spacing

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 FUNCTION

Error: Argument Order Mismatch

FUNCTION 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"