pub fn eval_apply(func: Value, arg: Value, pos: usize) -> ValueExpand description
func arg - applies a callable or indexable Swan value to an argument.
pos is the source position of the application, used in error values.
Dispatches on the type of func:
Value::Builtin(f): calls the native Rust function with the wholearg.Value::Func { ... }: creates a child scope of the closure, binds the parameters toarg(destructuring tuples, seeassignment_operation), and evaluates the body there.Value::List: indexing by a zero-based number. A tuple argument gives a tuple of results, normalized (so out-of-range indices are dropped).Value::Namespace: own-only lookup by text key. A tuple argument gives a normalized tuple of results (missing keys are dropped).Value::Text: character indexing by a zero-based number. A tuple argument gives a normalized tuple of results.- Anything else (including
NothingandUndefined): returnsUndef::BinaryOperation { op: "application", lhv: func, rhv: arg, pos }.
Broadcasting over a tuple of callables is not done here; the callers
(ApplicationOp, MappingOp) do it with map_values!.