Built-in Functions#

Examples demonstrating Bark’s built-in functions.

Core#

builtins/core/print.bark View on GitLab
// print(), println(), eprint(), eprintln() - Output functions
// print/println write to stdout, eprint/eprintln write to stderr
// ln variants add a newline after the output

// Basic println - most common output function
"Hello, World!" > println()

// print without newline - useful for prompts or inline output
"Enter name: " > print()

// Multiple values using format strings with {0}, {1} placeholders
println("Name: {0}, Age: {1}", "Alice", 30)

// String interpolation in the value being printed
"Bob" > name
42 > age
println("User {name} is {age} years old")

// eprint/eprintln write to stderr (for errors and diagnostics)
"Warning: low memory" > eprintln()
"Error: " > eprint()
"file not found" > eprintln()

// Chaining with other operations
5 > add(3) > println()  // Output: 8

// Printing different types
42 > println()           // integer
3.14 > println()         // float
true > println()         // boolean
[1, 2, 3] > println()    // array
{"a": 1} > println()     // map

Conditional Print#

builtins/core/print_conditional.bark View on GitLab
// print?(), println?(), eprint?(), eprintln?() - Conditional output
// Only prints when the first argument (condition) is true
// Useful for debug output or conditional logging

// Basic conditional print
true > println?("This prints")
false > println?("This does not print")

// With variables
true > shouldLog
shouldLog > println?("Logging enabled")

// Conditional debug output
fn process(value int, debug bool) {
  debug > println?("Processing value: {0}", value)
  value > mul(2) > result
  debug > println?("Result: {0}", result)
  return(result)
}(int)

// Run with debug on
10 > process(true) > result1
println("Final: {result1}")

// Run with debug off (no debug output)
10 > process(false) > result2
println("Final: {result2}")

// Conditional stderr output for errors
false > hasError
hasError > eprintln?("An error occurred!")

true > hasWarning
hasWarning > eprintln?("Warning: check your input")

// Useful in validation
fn validate(input string) {
  input > len() > inputLen
  inputLen > lt?(3) > tooShort
  tooShort > eprintln?("Input too short: {0}", input)
  tooShort > not() > return()
}(bool)

"ab" > validate() > valid1
println("'ab' valid: {valid1}")

"hello" > validate() > valid2
println("'hello' valid: {valid2}")

return#

builtins/core/return.bark View on GitLab
// return(value) - Exit function and return a value
// Can return single values, multiple values (tuple), or nothing

// Single return value
fn double(n int) {
  n > mul(2) > result
  return(result)
}(int)

5 > double() > println()  // Output: 10

// Return with no value (for side-effect functions)
fn greet(name string) {
  println("Hello, {name}!")
  return()
}()

"World" > greet()

// Multiple return values (tuple pattern)
fn divmod(a int, b int) {
  a > div(b) > quotient
  quotient > mul(b) > product
  a > sub(product) > remainder
  return(quotient, remainder)
}(int, int)


17 > divmod(5) > (q int, r int) {
  println("17 / 5 = {q} remainder {r}")
}()

// Early return pattern
fn find_positive(arr array) {
  arr > head() > (items array, idx int) {
    idx > lt?(0) > return?(-1)  // Empty array

    items > get(idx) > val
    val > gt?(0) > return?(val)  // Found positive

    items > next(idx) > nextIdx
    nextIdx > lt?(0) > return?(-1)  // End of array
    repeat(items, nextIdx)
  }(int) > result
  return(result)
}(int)

[-1, -2, 3, -4] > find_positive() > println()  // Output: 3
[-1, -2, -3] > find_positive() > println()     // Output: -1

to_string#

builtins/core/to_string.bark View on GitLab
// to_string(value) - Convert any value to its string representation
// Returns: string

// Convert integer to string
42 > to_string() > println()  // Output: 42

// Convert float to string
3.14159 > to_string() > println()  // Output: 3.14159

// Convert boolean to string
true > to_string() > println()   // Output: true
false > to_string() > println()  // Output: false

// Convert array to string
[1, 2, 3] > to_string() > println()  // Output: [1, 2, 3]

// Convert map to string
{"name": "Alice", "age": 30} > to_string() > println()

// Useful for string concatenation
"User ID: " > prefix
42 > to_string() > id_str
prefix > str.concat(id_str) > println()

// Store converted value
100 > to_string() > numStr
numStr > str.concat(" items") > println()  // Output: 100 items

Error Handling#

builtins/core/error.bark View on GitLab
// Error Handling Examples
// Demonstrates bark's error handling patterns with runnable code

// =============================================================================
// Error Handler Functions
// =============================================================================

// Error handlers take an error as first parameter
// Convention: names start with 'err_' (will be checked by linter)

fn err_file(err error) {
  eprintln("file operation failed: {err}")
  return(err)
}(error)

fn err_validation(err error) {
  eprintln("validation failed: {err}")
  return(err)
}(error)

fn err_validation_with_default(err error, val string) {
  eprintln("validation failed, using default: {err}")
  return("default_value")
}(string)

// =============================================================================
// Composable Validators
// =============================================================================

// Validators return (error, value) tuple - composable in chains
fn validateEmail(email string) {
  email > security.email?() > return?({}, email)
  err("invalid email format") > e
  return(e, "")
}(error, string)

fn validateEmailWithContext(email string) {
  email > security.email?() > return?({}, email)
  err("invalid email format", {"email": email, "reason": "format"}) > e
  return(e, "")
}(error, string)

fn validateAlphanumeric(input string) {
  input > str.alphanumeric?() > return?({}, input)
  err("input must be alphanumeric") > e
  return(e, "")
}(error, string)

// =============================================================================
// Error Context Manipulation
// =============================================================================

fn err_add_validation_context(err error) {
  time.now() > timestamp
  err > err_add_context("stage", "validation") >
       err_add_context("timestamp", timestamp) >
       return()
}(error)

fn err_log_details(err error) {
  err > err_msg() > msg
  eprintln("Error: {msg}")

  err > err_context() > ctx
  eprintln("Context: {ctx}")

  return(err)
}(error)

// =============================================================================
// Error Propagation Pattern
// =============================================================================

fn processUserInput(email string, username string) {
  // Validate email then username, propagate errors
  email > validateEmail() > (err1 error, validEmail string) {
    err1 > present?() > return?(err1, {})

    username > validateAlphanumeric() > (err2 error, validUsername string) {
      err2 > present?() > return?(err2, {})
      return({}, {"email": validEmail, "username": validUsername})
    }(error, map)
  }(error, map)
}(error, map)

// =============================================================================
// Execute Functions
// =============================================================================

println("=== Error Handling ===")

// Test err() builtin
err("test error") > e1
println("err(\"test error\") returns: {e1}")

// Test err() with context
err("test", {"key": "value"}) > e2
println("err(\"test\", {{\"key\": \"value\"}}) returns: {e2}")

// Test err_msg()
err("my message") > err_msg() > msg1
println("err(\"my message\") > err_msg() returns: {msg1}")

// Test err_context()
err("msg", {"a": 1}) > err_context() > ctx1
println("err(\"msg\", {{\"a\": 1}}) > err_context() returns: {ctx1}")

// Test err_add_context()
err("msg") > err_add_context("key", "val") > e3
println("err(\"msg\") > err_add_context(\"key\", \"val\") returns: {e3}")

// Test error handler functions
err("file not found") > err_file() > e4
println("err_file(err(\"file not found\")) returns: {e4}")

err("invalid input") > err_validation() > e5
println("err_validation(err(\"invalid input\")) returns: {e5}")

err("bad") > err_validation_with_default("fallback") > e6
println("err_validation_with_default(err(\"bad\"), \"fallback\") returns: {e6}")

// Test err_add_validation_context
err("test") > err_add_validation_context() > e7
println("err_add_validation_context(err(\"test\")) returns: {e7}")

// Test err_log_details
err("test", {"ctx": "data"}) > err_log_details() > e8
println("err_log_details(err(\"test\", {{\"ctx\": \"data\"}})) returns: {e8}")

// Test composable validators - valid email
println("validateEmail(\"user@example.com\"): ")
"user@example.com" > validateEmail() > (ve1 error, vv1 string) {
  println(ve1)
  println(vv1)
}()

// Test composable validators - invalid email
println("validateEmail(\"invalid\"): ")
"invalid" > validateEmail() > (ve2 error, vv2 string) {
  println(ve2)
  println(vv2)
}()

// Test composable validators - valid alphanumeric
println("validateAlphanumeric(\"user123\"): ")
"user123" > validateAlphanumeric() > (ve3 error, vv3 string) {
  println(ve3)
  println(vv3)
}()

// Test composable validators - invalid alphanumeric
println("validateAlphanumeric(\"user@123\"): ")
"user@123" > validateAlphanumeric() > (ve4 error, vv4 string) {
  println(ve4)
  println(vv4)
}()

// Test error propagation - valid input
println("processUserInput(\"user@example.com\", \"john123\"): ")
"user@example.com" > processUserInput("john123") > (perr1 error, presult1 map) {
  println(perr1)
  println(presult1)
}()

// Test error propagation - invalid input
println("processUserInput(\"invalid\", \"john123\"): ")
"invalid" > processUserInput("john123") > (perr2 error, presult2 map) {
  println(perr2)
  println(presult2)
}()

println("=== End of Error Handling Examples ===")

Control Flow#

repeat#

builtins/control_flow/repeat.bark View on GitLab
// Anonymous function recursion with repeat()
//
// Anonymous functions can recursively call themselves using repeat().
// They declare return types just like named functions and use return() to exit.
// Use tuples (value1, value2) to initialize anonymous functions with multiple parameters.

// Example 1: Factorial calculation using recursion
fn factorial(n int) {
  (n, 1) > (num int, acc int) {
    num > lte?(1) > return?(acc)

    num > sub(1) > next_num
    acc > mul(num) > next_acc
    repeat(next_num, next_acc)
  }(int) > result

  return(result)
}(int)

factorial(5) > println() // Output: 120

// How it works:
// - Call: factorial(5) > tuple (5, 1) initializes anonymous function with num=5, acc=1
// - Iteration 1: num=5 <= 1? false, next_num=4, next_acc=5, repeat(4, 5)
// - Iteration 2: num=4 <= 1? false, next_num=3, next_acc=20, repeat(3, 20)
// - Iteration 3: num=3 <= 1? false, next_num=2, next_acc=60, repeat(2, 60)
// - Iteration 4: num=2 <= 1? false, next_num=1, next_acc=120, repeat(1, 120)
// - Iteration 5: num=1 <= 1? true, return(120) -> returns 120

// Example 2: Sum of numbers from 1 to n
fn sum_to_n(n int) {
  (1, 0) > (current int, total int) {
    total > add(current) > new_total
    current > add(1) > next

    next > gt?(n) > return?(new_total)

    repeat(next, new_total)
  }(int) > result

  return(result)
}(int)
sum_to_n(10) > println() // Output: 55

// How it works:
// - Initial call: (1, 0)
// - Iteration 1: new_total=1, next=2, 2 > 10? false, repeat(2, 1)
// - Iteration 2: new_total=3, next=3, 3 > 10? false, repeat(3, 3)
// - ...
// - Iteration 10: new_total=55, next=11, 11 > 10? true, return(55) -> returns 55

// Example 3: Find first even number in a range
fn find_first_even(start int, end int) {
  start > (current int) {
    current > gt?(end) > return?(-1)  // Not found, return -1
    current > math.even?() > return?(current)  // Found, return the number

    current > add(1) > next
    repeat(next)
  }(int) > result

  return(result)
}(int)

find_first_even(7, 12) > println() // Output: 8
find_first_even(7, 7) > println() // Output: -1

// How it works:
// - Initial: current=7
// - 7 > 12? false, 7 even? false, next=8, repeat(8)
// - 8 > 12? false, 8 even? true, return(8) -> returns 8

// Example 4: Count down and print
fn countdown(n int) {
  n > (current int) {
	print(current)
    current > lte?(1) > return?()

    current > sub(1) > next
    repeat(next)
  }()

  println() // New line after countdown
}()

countdown(5) // Output: 54321

// How it works:
// - Iteration 1: prints "5", 5 <= 1? false, next=4, repeat(4)
// - Iteration 2: prints "4", 4 <= 1? false, next=3, repeat(3)
// - Iteration 3: prints "3", 3 <= 1? false, next=2, repeat(2)
// - Iteration 4: prints "2", 2 <= 1? false, next=1, repeat(1)
// - Iteration 5: prints "1", 1 <= 1? true, return() -> exits

// Example 5: Array iteration with recursion
fn sum_array(arr array) {
  (arr, 0, 0) > (items array, idx int, total int) {
    items > len() > arr_len
    idx > gte?(arr_len) > return?(total)

    items > get(idx) > value
    total > add(value) > new_total

    idx > add(1) > next_idx
    repeat(items, next_idx, new_total)
  }(int) > result

  return(result)
}(int)

sum_array([1, 2, 3, 4, 5]) > println() // Output: 15

// How it works:
// - Initial: tuple (arr, 0, 0) initializes items=arr, idx=0, total=0
// - Iteration 1: idx=0 >= 5? false, value=1, new_total=1, next_idx=1, repeat([...], 1, 1)
// - Iteration 2: idx=1 >= 5? false, value=2, new_total=3, next_idx=2, repeat([...], 2, 3)
// - ...
// - Final: idx=5 >= 5? true, return(15) -> returns 15

return?#

builtins/control_flow/return_conditional.bark View on GitLab
// return?(condition, value) - Conditional early return
// Returns the value only if condition is true
// If condition is false, continues execution

// Basic conditional return
fn check_positive(n int) {
  n > gt?(0) > return?("positive")
  n > lt?(0) > return?("negative")
  return("zero")
}(string)

5 > check_positive() > println() // Output: positive
-3 > check_positive() > println() // Output: negative
0 > check_positive() > println() // Output: zero

// Early exit on error condition
fn safe_divide(a int, b int) {
  b > eq?(0) > return?(0)  // Early return if dividing by zero
  a > div(b) > return()
}(int)

10 > safe_divide(2) > println() // Output: 5
10 > safe_divide(0) > println() // Output: 0

// Guard clauses pattern
fn process_user(user map) {
  user > empty?() > return?("no user")

  user > get("active") > isActive
  isActive > not() > return?("user inactive")

  user > get("name") > name
  return("processing {name}")
}(string)

{} > process_user() > println()
{"active": false, "name": "Bob"} > process_user() > println() // Output: user inactive
{"active": true, "name": "Alice"} > process_user() > println() // Output: processing Alice

// Multiple return values with return?
fn find_value(arr array, target int) {
  arr > head() > (items array, idx int) {
    idx > lt?(0) > return?(-1, false)  // Empty array

    items > get(idx) > val
    val > eq?(target) > return?(idx, true)  // Found

    items > next(idx) > nextIdx
    nextIdx > lt?(0) > return?(-1, false)  // Not found
    repeat(items, nextIdx)
  }(int, bool) > (foundIdx int, found bool) {
    return(foundIdx, found)
  }(int, bool)
}(int, bool)

[10, 20, 30] > find_value(20) > (idx int, found bool) {
  println("Index: {idx}, Found: {found}") // Output: Index: 1, Found: true
}()

break?#

builtins/control_flow/break_conditional.bark View on GitLab
// break?(condition, value) - Conditional exit from recursive anonymous function
// Similar to return? but specifically for exiting anonymous function recursion
// Stops recursion and returns value when condition is true

// Basic break? in recursion
fn countdown(n int) {
  n > (current int) {
    current > println()
    current > lte?(1) > break?()  // Exit when we reach 1

    current > sub(1) > next
    repeat(next)
  }()
}()

5 > countdown()
// Output: 5, 4, 3, 2, 1

// break? with return value
fn sum_until_limit(arr array, limit int) {
  (arr, 0, 0) > (items array, idx int, total int) {
    items > len() > arrLen
    idx > gte?(arrLen) > break?(total)  // End of array

    items > get(idx) > val
    total > add(val) > newTotal

    newTotal > gte?(limit) > break?(newTotal)  // Hit limit

    idx > add(1) > nextIdx
    repeat(items, nextIdx, newTotal)
  }(int) > result
  return(result)
}(int)

[10, 20, 30, 40, 50] > sum_until_limit(50) > println() // Output: 60 (10+20+30)
[1, 2, 3] > sum_until_limit(100) > println() // Output: 6 (all elements)

// break? vs return? in anonymous functions
// break? is used inside anonymous functions for early exit
// return? exits the entire enclosing named function

fn find_first_even(arr array) {
  arr > head() > (items array, idx int) {
    idx > lt?(0) > break?(-1)  // Empty array

    items > get(idx) > val
    val > math.even?() > break?(val)  // Found even number

    items > next(idx) > nextIdx
    nextIdx > lt?(0) > break?(-1)  // End of array, not found
    repeat(items, nextIdx)
  }(int) > result
  return(result)
}(int)

[1, 3, 4, 7] > find_first_even() > println() // Output: 4
[1, 3, 5, 7] > find_first_even() > println() // Output: -1

continue?#

builtins/control_flow/continue_conditional.bark View on GitLab
// continue?(condition) - Conditional chain continuation
// Continues chain if condition is true, stops chain if false
// Useful for filtering or short-circuit evaluation

// Basic continue? - stops chain when false
fn process_if_positive(n int) {
  n > gt?(0) > continue?()  // Stop if not positive
  n > mul(2) > println()
}()

5 > process_if_positive() // Output: 10
-3 > process_if_positive()// No output (chain stopped)

// Using continue? as a filter in processing
fn log_errors_only(level string, msg string) {
  level > eq?("error") > continue?() > println("[ERROR] {msg}")
}()

"info" > log_errors_only("System started") // No output
"error" > log_errors_only("Disk full") // Output: [ERROR] Disk full
"warn" > log_errors_only("Low memory") // No output

// Chain of validations
fn validate_and_process(value int) {
  value > gt?(0) > continue?()      // Must be positive
  value > lt?(100) > continue?()    // Must be less than 100
  value > mul(10) > println()       // Process valid values
}()

50 > validate_and_process()   // Output: 500
-5 > validate_and_process()   // No output (failed first check)
150 > validate_and_process()  // No output (failed second check)

// Conditional processing in a function
fn safe_log(enabled bool, msg string) {
  enabled > continue?()
  println("LOG: {msg}")
}()

true > safe_log("Debug mode active")   // Output: LOG: Debug mode active
false > safe_log("This won't print")   // No output

Numbers#

add#

builtins/numbers/add.bark View on GitLab
// add(n) - Add n to the piped value
// Returns: integer or float

// Basic integer addition
5 > add(3) > println()    // Output: 8

// Adding negative numbers
10 > add(-4) > println()  // Output: 6

// Chained additions
1 > add(2) > add(3) > add(4) > println()  // Output: 10

// Float addition
3.14 > add(1.86) > println()  // Output: 5.0

// Float addition (both operands must be same type)
5.0 > add(2.5) > println()  // Output: 7.5

sub#

builtins/numbers/sub.bark View on GitLab
// sub(n) - Subtract n from the piped value
// Returns: integer or float

// Basic integer subtraction
10 > sub(3) > println()    // Output: 7

// Subtracting negative numbers (effectively adds)
5 > sub(-2) > println()    // Output: 7

// Chained subtractions
20 > sub(5) > sub(3) > sub(2) > println()  // Output: 10

// Float subtraction
10.5 > sub(3.2) > println()  // Output: 7.3

// Result can be negative
3 > sub(7) > println()  // Output: -4

mul#

builtins/numbers/mul.bark View on GitLab
// mul(n) - Multiply the piped value by n
// Returns: integer or float

// Basic integer multiplication
5 > mul(3) > println()    // Output: 15

// Multiplying by negative numbers
4 > mul(-2) > println()   // Output: -8

// Chained multiplications
2 > mul(3) > mul(4) > println()  // Output: 24

// Float multiplication
2.5 > mul(4.0) > println()  // Output: 10.0

// Multiplying by zero
100 > mul(0) > println()  // Output: 0

// Negative times negative
-3 > mul(-4) > println()  // Output: 12

div#

builtins/numbers/div.bark View on GitLab
// div(n) - Divide the piped value by n
// Returns: integer or float (integer division truncates)

// Basic integer division
10 > div(2) > println()    // Output: 5

// Integer division truncates
7 > div(2) > println()     // Output: 3

// Float division preserves decimals
7.0 > div(2.0) > println() // Output: 3.5

// Chained divisions
100 > div(2) > div(5) > println()  // Output: 10

// Dividing by negative numbers
12 > div(-3) > println()   // Output: -4

// Negative divided by negative
-12 > div(-4) > println()  // Output: 3

Comparison#

eq / eq?#

builtins/comparison/eq.bark View on GitLab
// eq?(value) - Check if two values are equal
// Returns: boolean
// Note: Uses reference equality for arrays and maps

// Integer equality
5 > eq?(5) > println() // Output: true
5 > eq?(3) > println() // Output: false

// String equality
"hello" > eq?("hello") > println() // Output: true
"hello" > eq?("world") > println() // Output: false

// Boolean equality
true > eq?(true) > println() // Output: true
true > eq?(false) > println() // Output: false

// Float equality
3.14 > eq?(3.14) > println() // Output: true
3.14 > eq?(2.71) > println() // Output: false

// Zero equality
0 > eq?(0) > println() // Output: true
0.0 > eq?(0.0) > println() // Output: true

neq / neq?#

builtins/comparison/neq.bark View on GitLab
// neq?(value) - Check if two values are not equal
// Returns: boolean

// Integer inequality
5 > neq?(3) > println() // Output: true
5 > neq?(5) > println() // Output: false

// String inequality
"hello" > neq?("world") > println() // Output: true
"hello" > neq?("hello") > println() // Output: false

// Boolean inequality
true > neq?(false) > println() // Output: true
true > neq?(true) > println() // Output: false

// Array inequality
[1, 2, 3] > neq?([1, 2]) > println() // Output: true
[1, 2, 3] > neq?([1, 2, 3]) > println() // Output: false

// Useful for conditional logic
fn validate_name(name string) {
  name > neq?("") > return?("Name is valid")
  return("Name is empty")
}(string)

"Alice" > validate_name() > println() // Output: Name is valid
"" > validate_name() > println() // Output: Name is empty

lt / lt?#

builtins/comparison/lt.bark View on GitLab
// lt?(value) - Check if piped value is less than argument
// Returns: boolean

// Integer comparison
5 > lt?(10) > println() // Output: true
10 > lt?(5) > println() // Output: false
5 > lt?(5) > println() // Output: false (equal is not less)

// Float comparison
2.5 > lt?(3.0) > println() // Output: true
3.14 > lt?(3.14) > println() // Output: false

// Negative numbers
-5 > lt?(-1) > println() // Output: true
-1 > lt?(-5) > println() // Output: false

// Practical use: under threshold
fn check_inventory(count int) {
  count > lt?(10) > return?("Low stock - reorder needed")
  return("Stock OK")
}(string)

5 > check_inventory() > println() // Output: Low stock - reorder needed
15 > check_inventory() > println() // Output: Stock OK

lte / lte?#

builtins/comparison/lte.bark View on GitLab
// lte?(value) - Check if piped value is less than or equal to argument
// Returns: boolean

// Integer comparison
5 > lte?(10) > println() // Output: true
10 > lte?(5) > println() // Output: false
5 > lte?(5) > println() // Output: true (equal counts)

// Float comparison
3.0 > lte?(3.14) > println() // Output: true
3.14 > lte?(3.14) > println() // Output: true
// Negative numbers
-5 > lte?(0) > println() // Output: true
-5 > lte?(-5) > println() // Output: true

// Practical use: maximum threshold
fn check_budget(cost int) {
  cost > lte?(100) > return?("Within budget")
  return("Over budget")
}(string)

85 > check_budget() > println() // Output: Within budget
100 > check_budget() > println() // Output: Within budget
150 > check_budget() > println() // Output: Over budget

gt / gt?#

builtins/comparison/gt.bark View on GitLab
// gt?(value) - Check if piped value is greater than argument
// Returns: boolean

// Integer comparison
10 > gt?(5) > println() // Output: true
5 > gt?(10) > println() // Output: false
5 > gt?(5) > println() // Output: false (equal is not greater)

// Float comparison
3.14 > gt?(3.0) > println() // Output: true
2.5 > gt?(2.5) > println() // Output: false

// Negative numbers
-1 > gt?(-5) > println() // Output: true
-5 > gt?(-1) > println() // Output: false
// Float comparison (both operands must be same type)
10.0 > gt?(9.99) > println()  // Output: true

// Practical use: validation
fn check_age(age int) {
  age > gt?(17) > return?("Adult")
  return("Minor")
}(string)

21 > check_age() > println() // Output: Adult
15 > check_age() > println()// Output: Minor

gte / gte?#

builtins/comparison/gte.bark View on GitLab
// gte?(value) - Check if piped value is greater than or equal to argument
// Returns: boolean

// Integer comparison
10 > gte?(5) > println() // Output: true
5 > gte?(10) > println() // Output: false
5 > gte?(5) > println() // Output: true (equal counts)

// Float comparison
3.14 > gte?(3.14) > println() // Output: true
3.14 > gte?(3.0) > println() // Output: true

// Negative numbers
0 > gte?(-1) > println() // Output: true
-5 > gte?(-5) > println() // Output: true

// Practical use: minimum threshold
fn check_score(score int) {
  score > gte?(60) > return?("Pass")
  return("Fail")
}(string)

75 > check_score() > println() // Output: Pass
60 > check_score() > println() // Output: Pass
59 > check_score() > println() // Output: Fail

not / not?#

builtins/comparison/not.bark View on GitLab
// not() - Logical negation of boolean value
// Returns: boolean

// Basic negation
true > not() > println() // Output: false
false > not() > println() // Output: true

// Double negation
true > not() > not() > println() // Output: true

// Chained with other comparisons
5 > gt?(3) > not() > println() // Output: false (5 > 3 is true, not makes it false)
5 > lt?(3) > not() > println() // Output: true (5 < 3 is false, not makes it true)

// Practical use: inverse logic
fn is_invalid(value string) {
  value > eq?("") > not()
}(bool)

"hello" > is_invalid() > println() // Output: true (non-empty is "invalid" by this logic)
"" > is_invalid() > println() // Output: false

present / present?#

builtins/comparison/present.bark View on GitLab
// present?() - Check if value is present (not empty string, not empty collection)
// Returns: boolean

// Non-empty values are present
42 > present?() > println() // Output: true
"hello" > present?() > println() // Output: true
true > present?() > println() // Output: true
false > present?() > println() // Output: true (false is a value)

// Empty string is not present
"" > present?() > println() // Output: false

// Empty collections are not present
[] > present?() > println() // Output: false
{} > present?() > println() // Output: false

// Non-empty collections are present
[1, 2, 3] > present?() > println() // Output: true
{"key": "value"} > present?() > println() // Output: true

// Useful for error checking
fn handle_result(err map) {
  err > present?() > return?("Error occurred")
  return("Success")
}(string)

{} > handle_result() > println() // Output: Success
{"Msg": "Something went wrong"} > handle_result() > println() // Output: Error occurred

absent / absent?#

builtins/comparison/absent.bark View on GitLab
// absent?() - Check if value is absent (empty string or empty collection)
// Returns: boolean

// Empty string is absent
"" > absent?() > println() // Output: true

// Empty collections are absent
[] > absent?() > println() // Output: true
{} > absent?() > println() // Output: true

// Non-empty values are not absent
42 > absent?() > println() // Output: false
"hello" > absent?() > println() // Output: false
false > absent?() > println() // Output: false

// Non-empty collections are not absent
[1, 2] > absent?() > println() // Output: false
{"a": 1} > absent?() > println() // Output: false

// Useful for success checking (empty error = success)
fn check_success(err map) {
  err > absent?() > return?("Operation succeeded")
  return("Operation failed")
}(string)

{} > check_success() > println() // Output: Operation succeeded
{"Msg": "Error"} > check_success() > println() // Output: Operation failed

Arrays#

len#

builtins/arrays/len.bark View on GitLab
// len() - Get the length of an array or string
// Returns: integer
// Note: For maps, use size() instead

// Array length
[1, 2, 3, 4, 5] > len() > println() // Output: 5

// Empty array
[] > len() > println() // Output: 0

// String length
"hello" > len() > println() // Output: 5

// Empty string
"" > len() > println() // Output: 0

// For maps, use size() instead of len()
{"a": 1, "b": 2, "c": 3} > size() > println() // Output: 3

// Empty map
{} > size() > println() // Output: 0

// Nested arrays (counts top-level elements)
[[1, 2], [3, 4], [5]] > len() > println() // Output: 3

empty / empty?#

builtins/arrays/empty.bark View on GitLab
// empty?() - Check if collection or string is empty
// Returns: boolean

// Empty array
[] > empty?() > println() // Output: true

// Non-empty array
[1, 2, 3] > empty?() > println() // Output: false

// Empty string
"" > empty?() > println() // Output: true

// Non-empty string
"hello" > empty?() > println() // Output: false

// Empty map
{} > empty?() > println() // Output: true

// Non-empty map
{"key": "value"} > empty?() > println() // Output: false

// Practical use: conditional logic
fn check_list(items array) {
  items > empty?() > return?("List is empty")
  items > len() > to_string() > str.concat(" items found") > return()
}(string)

[] > check_list() > println() // Output: List is empty
[1, 2, 3] > check_list() > println() // Output: 3 items found

Data Structures#

get#

builtins/data_structures/get.bark View on GitLab
// get(collection, key) - Retrieve value from array or map
// For arrays: key is integer index
// For maps: key is string
// Returns execution error if key/index not found

// Array access by index
[10, 20, 30] > get(0) > println()  // Output: 10
[10, 20, 30] > get(2) > println()  // Output: 30

// Map access by key
{"name": "Alice", "age": 30} > get("name") > println()  // Output: Alice
{"name": "Alice", "age": 30} > get("age") > println()   // Output: 30

// Chained access for nested structures
{"user": {"name": "Bob"}} > get("user") > get("name") > println()  // Output: Bob

// Array of maps
[{"id": 1}, {"id": 2}] > get(1) > get("id") > println()  // Output: 2

// Store retrieved value
{"status": "active"} > get("status") > status
println("Status is: {status}")

// Use in calculations
[5, 10, 15] > arr
arr > get(0) > first_val
arr > get(2) > last_val
first_val > add(last_val) > println()  // Output: 20

// Note: Out of bounds access returns execution error
// [1, 2, 3] > get(5) > println()  // Would return error

set#

builtins/data_structures/set.bark View on GitLab
// set(collection, key, value) - Set value in array or map
// For arrays: key is integer index (must be valid)
// For maps: key is string (creates or updates)
// Returns the modified collection

// Set array element
[1, 2, 3] > set(1, 99) > println()  // Output: [1, 99, 3]

// Set map value (update existing)
{"name": "Alice"} > set("name", "Bob") > println()  // Output: {"name": "Bob"}

// Set map value (add new key)
{"name": "Alice"} > set("age", 30) > println()  // Output: {"name": "Alice", "age": 30}

// Chained sets
{} > set("a", 1) > set("b", 2) > set("c", 3) > println() // Output: {"a": 1, "b": 2, "c": 3}

// Update array in a chain
[0, 0, 0] > set(0, 1) > set(1, 2) > set(2, 3) > println() // Output: [1, 2, 3]

// Store modified collection
{"count": 0} > data
data > set("count", 42) > data
println("Updated data: {data}")

// Nested map update
{"user": {"name": "Alice"}} > outer
outer > get("user") > set("name", "Bob") > inner
outer > set("user", inner) > println()

size#

builtins/data_structures/size.bark View on GitLab
// size(collection) - Get number of elements in collection
// Works on arrays, maps, and strings
// Returns: integer

// Array size
[1, 2, 3, 4, 5] > size() > println()  // Output: 5
[] > size() > println()               // Output: 0

// Map size (number of key-value pairs)
{"a": 1, "b": 2, "c": 3} > size() > println()  // Output: 3
{} > size() > println()                         // Output: 0

// String size (number of characters)
"hello" > size() > println()  // Output: 5
"" > size() > println()       // Output: 0

// Unicode string size
"hello" > size() > println()  // Output: 5

// Conditional based on size
fn describe_collection(arr array) {
  arr > size() > s
  s > eq?(0) > return?("empty")
  s > eq?(1) > return?("single element")
  s > lt?(5) > return?("small collection")
  return("large collection")
}(string)

[] > describe_collection() > println()           // Output: empty
[1] > describe_collection() > println()          // Output: single element
[1, 2, 3] > describe_collection() > println()    // Output: small collection
[1, 2, 3, 4, 5, 6] > describe_collection() > println()  // Output: large collection

// Note: size() is an alias for len() that works consistently
// across arrays, maps, and strings

first#

builtins/data_structures/first.bark View on GitLab
// first(collection) - Get first element with its key/index
// For arrays: returns [index, value] where index is 0 or -1 if empty
// For maps: returns [key, value] where key is "" if empty

// Array first element
[10, 20, 30] > first() > println()  // Output: [0, 10]

// Empty array
[] > first() > println()  // Output: [-1, 0]

// Map first entry (insertion order)
{"a": 1, "b": 2, "c": 3} > first() > println()  // Output: ["a", 1]

// Empty map
{} > first() > println()  // Output: ["", 0]

// Destructure the result
["apple", "banana", "cherry"] > first() > (arr array) { // first() returns [index, value]
  arr > get(1) > val
  println("Index: {1}, Value: {val}")
}()

// Check if collection has elements
fn has_elements(arr array) {
  arr > present?() > return()
}(bool)

[1, 2, 3] > has_elements() > println()  // Output: true
[] > has_elements() > println()         // Output: false

// Get first value directly
["first", "second"] > first() > get(1) > println()  // Output: first

last#

builtins/data_structures/last.bark View on GitLab
// last(collection) - Get last element with its key/index
// For arrays: returns [index, value] where index is -1 if empty
// For maps: returns [key, value] where key is "" if empty

// Array last element
[10, 20, 30] > last() > println()  // Output: [2, 30]

// Empty array
[] > last() > println()  // Output: [-1, 0]

// Map last entry (insertion order)
{"a": 1, "b": 2, "c": 3} > last() > println()  // Output: ["c", 3]

// Empty map
{} > last() > println()  // Output: ["", 0]

// Destructure the result
["apple", "banana", "cherry"] > last() > (arr array) {
  arr > get(0) > val
  println("Index: {0}, Value: {val}") // Output: Index: 2, Value: cherry
}()

// Get the last value from an array
[1, 2, 3, 4, 5] > last() > get(1) > println()  // Output: 5

// Useful for stack-like operations
fn peek(stack array) {
  stack > last() > get(1) > return()
}(map)

[{"task": "first"}, {"task": "second"}] > peek() > println()
// Output: {"task": "second"}

includes / includes?#

builtins/data_structures/includes.bark View on GitLab
// includes?(collection, value) - Check if collection contains value
// For arrays: checks if any element equals value
// For strings: checks if substring exists
// Returns: boolean

// Array includes
[1, 2, 3, 4, 5] > includes?(3) > println()  // Output: true
[1, 2, 3, 4, 5] > includes?(9) > println()  // Output: false

// String includes (substring check)
"hello world" > includes?("world") > println()  // Output: true
"hello world" > includes?("xyz") > println()    // Output: false

// Check for string in array
["apple", "banana", "cherry"] > includes?("banana") > println()  // Output: true
["apple", "banana", "cherry"] > includes?("grape") > println()   // Output: false

// Conditional logic with includes
fn is_admin(roles array) {
  roles > includes?("admin") > return()
}(bool)

["user", "editor"] > is_admin() > println()        // Output: false
["user", "admin", "editor"] > is_admin() > println()  // Output: true

// Validate input against allowed values
fn validate_color(color string) {
  ["red", "green", "blue"] > includes?(color) > return()
}(bool)

"red" > validate_color() > println()     // Output: true
"yellow" > validate_color() > println()  // Output: false

// Check substring in validation
fn has_domain(email string) {
  email > includes?("@") > return()
}(bool)

"user@example.com" > has_domain() > println()  // Output: true
"invalid" > has_domain() > println()           // Output: false

excludes / excludes?#

builtins/data_structures/excludes.bark View on GitLab
// excludes?(collection, value) - Check if collection does NOT contain value
// For arrays: checks that no element equals value
// For strings: checks that substring does NOT exist
// Returns: boolean (opposite of includes?)

// Array excludes
[1, 2, 3, 4, 5] > excludes?(9) > println()  // Output: true
[1, 2, 3, 4, 5] > excludes?(3) > println()  // Output: false

// String excludes (no substring)
"hello world" > excludes?("xyz") > println()    // Output: true
"hello world" > excludes?("world") > println()  // Output: false

// Validate exclusion
fn is_not_blocked(username string) {
  ["admin", "root", "system"] > excludes?(username) > return()
}(bool)

"john" > is_not_blocked() > println()   // Output: true
"admin" > is_not_blocked() > println()  // Output: false

// Check for dangerous characters
fn is_safe_input(input string) {
  input > excludes?("<script>") > return()
}(bool)

"Hello, user!" > is_safe_input() > println()       // Output: true
"<script>alert(1)</script>" > is_safe_input() > println()  // Output: false

// Ensure array doesn't contain duplicates (check before adding)
fn can_add(items array, newItem string) {
  items > excludes?(newItem) > return()
}(bool)

["a", "b", "c"] > can_add("d") > println()  // Output: true
["a", "b", "c"] > can_add("b") > println()  // Output: false

// Validation guard
fn validate_no_spaces(input string) {
  input > excludes?(" ") > valid
  valid > return?(input)
  return("")
}(string)

"hello" > validate_no_spaces() > println()        // Output: hello
"hello world" > validate_no_spaces() > println()  // Output: (empty)
builtins/data_structures/head.bark View on GitLab
// head(collection) - Get collection with cursor at first position
// Returns tuple: (collection, first_key_or_index)
// For arrays: returns (array, 0) or (array, -1) if empty
// For maps: returns (map, first_key) or (map, "") if empty
// Useful for starting iteration

// Array head
[10, 20, 30] > head() > capture(arry, idx)
println("Array: {arry}, Index: {idx}")  // Output: Array: [10, 20, 30], Index: 0

// Empty array
[] > head() > capture(arry, idx)
println("Array: {arry}, Index: {idx}")  // Output: Array: [], Index: -1

// Map head
{"a": 1, "b": 2} > head() > capture(m, k)
println("Map: {m}, First key: {k}")  // Output: ({"a": 1, "b": 2}, "a")

// Empty map
{} > head() > capture(m, k)
println("Map: {m}, First key: {k}")  // Output: ({}, "")

// Iteration pattern with head
fn sum_all(arr array) {
  arr > head() > (items array, idx int) {
    idx > lt?(0) > break?(0)  // Empty array

    items > get(idx) > val
    0 > total

    (items, idx, total) > (a array, i int, t int) {
      a > get(i) > v
      t > add(v) > newTotal

      a > next(i) > nextIdx
      nextIdx > lt?(0) > break?(newTotal)
      repeat(a, nextIdx, newTotal)
    }(int) > result
    return(result)
  }(int) > finalResult
  return(finalResult)
}(int)

[1, 2, 3, 4, 5] > sum_all() > println()  // Output: 15

// Destructure head result
{"x": 10, "y": 20} > head() > (m map, k string) {
  println("Map: {m}")
  println("First key: {k}")
}()

tail#

builtins/data_structures/tail.bark View on GitLab
// tail(collection) - Get collection with cursor at last position
// Returns tuple: (collection, last_key_or_index)
// For arrays: returns (array, last_index) or (array, -1) if empty
// For maps: returns (map, last_key) or (map, "") if empty
// Useful for reverse iteration

// Array tail
[10, 20, 30] > tail() > capture(arr, idx)
println("Array: {arr}, Index: {idx}")  // Output: Array: [10, 20, 30], Index: 2

// Empty array
[] > tail() > capture(arr, idx)
println("Array: {arr}, Index: {idx}")  // Output: Array: [], Index: -1

// Map tail
{"a": 1, "b": 2, "c": 3} > tail() > capture(m, k)
println("Map: {m}, Last key: {k}")  // Output: Map: {"a": 1, "b": 2, "c": 3}, Last key: c

// Empty map
{} > tail() > capture(m, k)
println("Map: {m}, Last key: {k}")  // Output: Map: {}, Last key:

// Reverse iteration pattern with tail
fn print_reverse(arr array) {
  arr > tail() > (items array, idx int) {
    idx > lt?(0) > break?()  // Empty array

    items > get(idx) > val
    println(val)

    items > prev(idx) > prevIdx
    prevIdx > lt?(0) > break?()
    repeat(items, prevIdx)
  }()
}()

["first", "second", "third"] > print_reverse()
// Output:
// third
// second
// first

// Find last matching element
fn find_last_positive(arr array) {
  arr > tail() > (items array, idx int) {
    idx > lt?(0) > break?(-1)  // Empty

    items > get(idx) > val
    val > gt?(0) > break?(val)  // Found

    items > prev(idx) > prevIdx
    prevIdx > lt?(0) > break?(-1)  // Not found
    repeat(items, prevIdx)
  }(int) > result
  return(result)
}(int)

[-1, 5, -2, 3, -4] > find_last_positive() > println()  // Output: 3

next#

builtins/data_structures/next.bark View on GitLab
// next(collection, key) - Get the next key/index after current position
// For arrays: returns next index or -1 if at end
// For maps: returns next key or "" if at end

// Array next index
[10, 20, 30] > next(0) > println()  // Output: 1
[10, 20, 30] > next(1) > println()  // Output: 2
[10, 20, 30] > next(2) > println()  // Output: -1 (at end)

// Map next key
{"a": 1, "b": 2, "c": 3} > next("a") > println()  // Output: b
{"a": 1, "b": 2, "c": 3} > next("b") > println()  // Output: c
{"a": 1, "b": 2, "c": 3} > next("c") > println()  // Output: "" (at end)

// Iterate using next
fn print_all(arr array) {
  arr > head() > (items array, idx int) {
    idx > lt?(0) > return?()  // Empty array

    items > get(idx) > val
    println("arr[{idx}] = {val}")

    items > next(idx) > nextIdx
    nextIdx > lt?(0) > return?()  // End of array
    repeat(items, nextIdx)
  }()
}()

[100, 200, 300] > print_all()
// Output:
// arr[0] = 100
// arr[1] = 200
// arr[2] = 300

// Check if there's a next element
fn has_next(arr array, idx int) {
  arr > next(idx) > nextIdx
  nextIdx > gte?(0) > return()
}(bool)

[1, 2, 3] > has_next(1) > println()  // Output: true
[1, 2, 3] > has_next(2) > println()  // Output: false

prev#

builtins/data_structures/prev.bark View on GitLab
// prev(collection, key) - Get the previous key/index before current position
// For arrays: returns previous index or -1 if at start
// For maps: returns previous key or "" if at start

// Array previous index
[10, 20, 30] > prev(2) > println()  // Output: 1
[10, 20, 30] > prev(1) > println()  // Output: 0
[10, 20, 30] > prev(0) > println()  // Output: -1 (at start)

// Map previous key
{"a": 1, "b": 2, "c": 3} > prev("c") > println()  // Output: b
{"a": 1, "b": 2, "c": 3} > prev("b") > println()  // Output: a
{"a": 1, "b": 2, "c": 3} > prev("a") > println()  // Output: "" (at start)

// Reverse iteration using prev
fn print_reverse(arr array) {
  arr > len() > sub(1) > lastIdx
  (arr, lastIdx) > (items array, idx int) {
    idx > lt?(0) > return?()  // Empty array

    items > get(idx) > val
    println("arr[{idx}] = {val}")

    items > prev(idx) > prevIdx
    prevIdx > lt?(0) > return?()  // Start of array
    repeat(items, prevIdx)
  }()
}()

[100, 200, 300] > print_reverse()
// Output:
// arr[2] = 300
// arr[1] = 200
// arr[0] = 100

// Check if there's a previous element
fn has_prev(arr array, idx int) {
  arr > prev(idx) > prevIdx
  prevIdx > gte?(0) > return()
}(bool)

[1, 2, 3] > has_prev(1) > println()  // Output: true
[1, 2, 3] > has_prev(0) > println()  // Output: false

reverse#

builtins/data_structures/reverse.bark View on GitLab
// reverse(collection) - Reverse order of elements
// Works on arrays and strings
// Returns: new reversed collection

// Reverse array
[1, 2, 3, 4, 5] > reverse() > println()  // Output: [5, 4, 3, 2, 1]

// Reverse string
"hello" > reverse() > println()  // Output: olleh

// Empty collections
[] > reverse() > println()  // Output: []
"" > reverse() > println()  // Output: (empty string)

// Single element
[42] > reverse() > println()  // Output: [42]
"x" > reverse() > println()   // Output: x

// Reverse and process
["first", "second", "third"] > reverse() > each((items array, idx int) {
  items > get(idx) > println()
}())
// Output:
// third
// second
// first

// Check for palindrome
fn is_palindrome(s string) {
  s > reverse() > reversed
  s > eq?(reversed) > return()
}(bool)

"racecar" > is_palindrome() > println()  // Output: true
"hello" > is_palindrome() > println()    // Output: false

// Reverse twice returns original
[1, 2, 3] > reverse() > reverse() > println()  // Output: [1, 2, 3]

// Process array from end to start
fn process_lifo(stack array) {
  stack > reverse() > each((items array, idx int) {
    items > get(idx) > val
    println("Processing: {val}")
  }())
}()

["task1", "task2", "task3"] > process_lifo()
// Output:
// Processing: task3
// Processing: task2
// Processing: task1

Iteration Patterns#

builtins/data_structures/iteration.bark View on GitLab
// Data structures examples - maps and arrays

// =============================================================================
// Map Literals
// =============================================================================

// Empty map
{}

// Map with string values
{"name": "john", "city": "seattle"}

// Map with mixed values
{"count": 42, "name": "test", "active": true}

// Nested maps
{"user": {"name": "john", "age": 30}}

// =============================================================================
// Array Literals
// =============================================================================

// Empty array
[]

// Array with integers
[1, 2, 3, 4]

// Array with strings
["apple", "banana", "cherry"]

// Nested arrays
[1, [2, 3], [4, [5, 6]]]

// =============================================================================
// Map Iteration
// =============================================================================

// Print all entries in a map
fn print_map(data map) {
  data > each((m map, k string) {
    m > get(k) > v
    println("{k}: {v}")
  }())
}

// Transform all map values
fn uppercase_all_values(data map) {
  data > head() > (m map, k string) {
    k > absent?() > break?(data)  // Exit if empty map, return data

    m > get(k) > str.upper() > upper
    m > set(k, upper)

    m > next(k) > nextKey > absent?() > break?()
    repeat(m, nextKey)
  }()

  return(data)
}(map)

// Find entry by value (early exit)
fn find_admin(users map) {
  users > head() > (m map, username string) {
    username > absent?() > break?("")  // Empty map, return empty string

    m > get(username) > user
    user > get("admin") > isAdmin

    isAdmin > return?(username)  // Found admin, return username

    m > next(username) > nextKey > absent?() > break?("")  // Not found
    repeat(m, nextKey)
  }()

  return("")
}(string)

// Count matching entries
fn count_active_users(users map) {
  (users, 0) > (m map, count int) {
    m > head() > (data map, username string) {
      username > absent?() > break?(count)  // Empty map, return count

      data > get(username) > user
      user > get("active") > isActive

      // Conditionally increment count
      count > add(1) > incremented
      isActive > (active bool) {
        active > return?(incremented)
        return(count)
      }(int) > new_count

      data > next(username) > nextKey
      nextKey > absent?() > break?(new_count)
      repeat(data, nextKey, new_count)
    }(int) > result
    return(result)
  }(int) > final_count

  return(final_count)
}(int)

// =============================================================================
// Array Iteration
// =============================================================================

// Print all array elements
fn print_array(items array) {
  items > each((arr array, idx int) {
    arr > get(idx) > val
    println("{idx}: {val}")
  }())
}

// Double all array values
fn double_all(nums array) {
  nums > head() > (arr array, idx int) {
    idx > lt?(0) > break?(nums)  // Exit if empty array, return nums

    arr > get(idx) > mul(2) > doubled
    arr > set(idx, doubled)

    arr > next(idx) > nextIdx > lt?(0) > break?()
    repeat(arr, nextIdx)
  }()

  return(nums)
}(array)

// Find first matching element
fn find_admin_user(users array) {
  users > head() > (arr array, idx int) {
    idx > lt?(0) > break?({})  // Empty array, return empty map

    arr > get(idx) > user
    user > get("admin") > isAdmin

    isAdmin > return?(user)  // Found it, return user

    arr > next(idx) > nextIdx > lt?(0) > break?({})  // Not found
    repeat(arr, nextIdx)
  }()
}(map)

// Sum all elements
fn sum(nums array) {
  0 > total
  nums > head() > (arr array, idx int) {
    idx > lt?(0) > break?(total)  // Empty array, return total (0)

    arr > get(idx) > val
    total > add(val) > total

    arr > next(idx) > nextIdx > lt?(0) > break?()
    repeat(arr, nextIdx)
  }()

  return(total)
}(int)

// Build new array from transformation
fn uppercase_all_strings(words array) {
  [] > result
  words > head() > (arr array, idx int) {
    idx > lt?(0) > break?(result)  // Empty array, return result ([])

    arr > get(idx) > str.upper() > upper
    result > array.push(upper)

    arr > next(idx) > nextIdx > lt?(0) > break?()
    repeat(arr, nextIdx)
  }()

  return(result)
}(array)

// =============================================================================
// Reverse Iteration
// =============================================================================

// Print array in reverse
fn print_array_reverse(items array) {
  items > reverse() > each((arr array, idx int) {
    arr > get(idx) > println()
  }())
}

// =============================================================================
// Execute Functions
// =============================================================================

println("=== Data Structures ===")

// Map literals
{} > empty_map
println("Empty map: {empty_map}")

{"name": "john", "city": "seattle"} > str_map
println("Map with string values: {str_map}")

{"count": 42, "name": "test", "active": true} > mixed_map
println("Map with mixed values: {mixed_map}")

{"user": {"name": "john", "age": 30}} > nested_map
println("Nested maps: {nested_map}")

// Array literals
[] > empty_arr
println("Empty array: {empty_arr}")

[1, 2, 3, 4] > int_arr
println("Array with integers: {int_arr}")

["apple", "banana", "cherry"] > str_arr
println("Array with strings: {str_arr}")

[1, [2, 3], [4, [5, 6]]] > nested_arr
println("Nested arrays: {nested_arr}")

// Map iteration functions
println("print_map({\"a\": 1, \"b\": 2}): ")
{"a": 1, "b": 2} > print_map()

{"a": "hello", "b": "world"} > uppercase_all_values() > result1
println("uppercase_all_values({{\"a\": \"hello\", \"b\": \"world\"}}): {result1}")

{"alice": {"admin": false}, "bob": {"admin": true}} > find_admin() > result2
println("find_admin({{\"alice\": {{\"admin\": false}}, \"bob\": {{\"admin\": true}}}}): {result2}")

{"u1": {"active": true}, "u2": {"active": false}, "u3": {"active": true}} > count_active_users() > result3
println("count_active_users({{\"u1\": {{\"active\": true}}, \"u2\": {{\"active\": false}}, \"u3\": {{\"active\": true}}}}): {result3}")

// Array iteration functions
println("print_array([\"a\", \"b\", \"c\"]): ")
["a", "b", "c"] > print_array()

[1, 2, 3, 4] > double_all() > result4
println("double_all([1, 2, 3, 4]): {result4}")

[{"name": "alice", "admin": false}, {"name": "bob", "admin": true}] > find_admin_user() > result5
println("find_admin_user([{{\"name\": \"alice\", \"admin\": false}}, {{\"name\": \"bob\", \"admin\": true}}]): {result5}")

[1, 2, 3, 4, 5] > sum() > result6
println("sum([1, 2, 3, 4, 5]): {result6}")

["hello", "world"] > uppercase_all_strings() > result7
println("uppercase_all_strings([\"hello\", \"world\"]): {result7}")

// Reverse iteration
println("print_array_reverse([\"a\", \"b\", \"c\"]): ")
["a", "b", "c"] > print_array_reverse()