boxlang-functional-programminglisted
Install: claude install-skill ortus-boxlang/skills
# BoxLang Functional Programming
## Overview
BoxLang treats functions as first-class values. Functions can be stored in variables,
passed as arguments, returned from other functions, and used in functional pipelines.
BoxLang supports closures, lambdas, and arrow functions with a clean, expressive syntax.
## Closures vs Lambdas — Critical Distinction
**This distinction matters for correctness:**
| Syntax | Name | Scope Capture | Use When |
|--------|------|---------------|----------|
| `(args) => expr` | Closure | ✅ Yes — captures surrounding scope | Accesses outer variables or calls external functions/BIFs |
| `(args) -> expr` | Lambda | ❌ No — only uses its own args | Purely deterministic; only works with passed arguments |
| `function(...) {}` | UDF/Closure | ✅ Yes — when assigned to a variable/returned | Named or complex multi-line function bodies |
```boxlang
var multiplier = 10
// ✅ Closure (=>) — captures 'multiplier' from outer scope
var scale = ( n ) => n * multiplier
scale( 5 ) // 50
// ✅ Lambda (->) — does NOT capture, only uses its own arguments
var double = ( n ) -> n * 2
double( 5 ) // 10
// ❌ WRONG — lambda trying to access outer 'multiplier' will fail
var scale = ( n ) -> n * multiplier // Error! multiplier not in lambda scope
```
**Rule of thumb:** If the function body references any variable from the surrounding scope
or calls external functions/BIFs (like `now()`, `writeLog()`, etc.), use `=>` (closure).
If it only processes its own arguments,