' Optional Params — OPTIONAL parameters with default handling
#COMPILE EXE
#DIM ALL

FUNCTION MakeGreeting(name AS STRING, OPTIONAL greeting AS STRING) AS STRING
    LOCAL g AS STRING

    IF ISMISSING(greeting) THEN
        g = "Hello"
    ELSE
        g = greeting
    END IF

    FUNCTION = g + ", " + name + "!"
END FUNCTION

FUNCTION Power(base AS DOUBLE, OPTIONAL exponent AS DOUBLE) AS DOUBLE
    LOCAL e AS DOUBLE

    IF ISMISSING(exponent) THEN
        e = 2.0
    ELSE
        e = exponent
    END IF

    FUNCTION = base ^ e
END FUNCTION

FUNCTION PBMAIN() AS LONG
    LOCAL r1 AS STRING
    LOCAL r2 AS STRING
    LOCAL r3 AS STRING
    LOCAL p1 AS DOUBLE
    LOCAL p2 AS DOUBLE
    LOCAL p3 AS DOUBLE

    r1 = MakeGreeting("Alice")
    PRINT "MakeGreeting(Alice): " + r1
    r2 = MakeGreeting("Bob", "Hi")
    PRINT "MakeGreeting(Bob,Hi): " + r2
    r3 = MakeGreeting("Carol", "Good day")
    PRINT "MakeGreeting(Carol,Good day): " + r3
    PRINT
    p1 = Power(5.0)
    PRINT "Power(5.0): " + STR$(p1)
    p2 = Power(2.0, 10.0)
    PRINT "Power(2.0,10.0): " + STR$(p2)
    p3 = Power(3.0, 3.0)
    PRINT "Power(3.0,3.0): " + STR$(p3)

    FUNCTION = 0
END FUNCTION
