Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.24 KB

File metadata and controls

50 lines (35 loc) · 1.24 KB

Function Calls

Named Arguments Requirement

Functions with more than one parameter must be called with named arguments.

Valid Function Calls

// Zero parameters
fn getValue() = 42
let value = getValue()

// Single parameter - positional allowed
fn double(x) = x * 2
let result = double(5)

// Multiple parameters - named arguments required
fn add(x, y) = x + y
let sum = add(x: 10, y: 20)

// Order doesn't matter with named arguments
let sum2 = add(y: 20, x: 10)

// Works with type annotations
fn multiply(a: int, b: int) -> int = a * b
let product = multiply(a: 5, b: 3)

Invalid Function Calls

// ERROR: Multi-parameter function with positional arguments
fn add(x, y) = x + y
let sum = add(10, 20)  // Compilation error

// ERROR: Mixed positional and named arguments
let sum = add(10, y: 20)  // Compilation error

// ERROR: Missing parameter name
let result = multiply(5, b: 3)  // Compilation error

Rules

  1. Zero parameters: empty parentheses, f().
  2. One parameter: positional or named.
  3. Two or more parameters: every argument must be named. Mixing positional and named arguments is a compilation error.

Argument order at the call site is independent of declaration order; the compiler reorders by name.