# lib_anon function library

Dependencies: lib_fn, lib_sugar, lib_tools

## Description

The anonymous function construct. Functions here should build and apply anonymous functions, and not interact with IE resources.

Functions here should start with 'anon_'.

## Public functions

anon_check(has_output:i, function:s, input:s=arguments, output:s=value, prepend:s, append:s)=(function:s, SFO_anon_func_count:s) dimorphic

Check if 'function' is an anonymous function definition, and if so create it and return its name; if not, return 'function' itself.

A string is an anonymous function definition if it contains any of these: [ <>/=+*{}]. (If you somehow manage to define an anonymous function that doesn't use any of these, just add a space at the beginning.)

anon_define(has_output:b, action_function:b, return_array:b, function:s, input:s=arguments, output:s=value, prepend:s, append:s)=(function:s, SFO_anon_func_count:s) dimorphic

Define the string 'function' as an anonymous patch function (setting its single STR_VAR input to 'input' and its single output to 'output'), and return the name of the function and an integer keeping track of how many anonymous functions have been defined.

The point of the integer is to avoid namespace collisions. By leaving it in scope for other calls of anon_define, we guarantee distinct functions.

We allow the following syntactic sugar for anon_define:

- '__' evaluates to '%input%' - 'SFO_args' evaluates to 'input' - '{' and '

anon_eval(has_output:i, arguments:s, function:s, append:s, prepend:s)=(value:s) action
anon_eval(has_output:i, arguments:s, function:s, append:s, prepend:s)=(value:s) patch

Evaluate 'function' as an anonymous patch function, apply it to 'arguments', and return the result. NB: anon_eval is not dimorphic. The action version runs on a blank patch. The patch version runs on whatever is currently being patched.