1//////////////////////////////////////////////////////////////////////
   2// LibFile: fnliterals.scad
   3//   Handlers for function literals, and Function literal generators.
   4// Includes:
   5//   include <BOSL2/std.scad>
   6//   include <BOSL2/fnliterals.scad>
   7// FileGroup: Data Management
   8// FileSummary: Function Literal Algorithms, and factories for generating function literals for builtin functions.
   9// DefineHeader(Table;Headers=Positional|Definition||Named|Definition): FunctionLiteral Args
  10//////////////////////////////////////////////////////////////////////
  11
  12
  13//////////////////////////////////////////////////////////////////////
  14// Section: Function Literal Algorithms
  15
  16
  17// Function: map()
  18// Synopsis: Applies a function to each item in a list.
  19// Topics: Function Literals, Looping
  20// See Also: filter(), reduce(), accumulate(), while(), for_n()
  21// Usage:
  22//   lst = map(func, list);
  23//   lst = map(function (x) x+1, list);
  24// Description:
  25//   Applies the function `func` to all items in `list`, returning the list of results.
  26//   In pseudo-code, this is effectively:
  27//   ```
  28//   function map(func,list):
  29//       out = [];
  30//       foreach item in list:
  31//           append func(item) to out;
  32//       return out;
  33//   ```
  34// Arguments:
  35//   func = The function of signature (x) to evaluate for each item in `list`.
  36//   list = The input list.
  37// Example:
  38//   func = function(x) x*x;
  39//   echo(map(func, [1,2,3,4]));
  40//   // ECHO: [1,4,9,16]
  41// Example:
  42//   path = star(n=5,step=2,d=100);
  43//   seglens = map(function (p) norm(p[1]-p[0]), pair(path,wrap=true));
  44function map(func, list) =
  45    assert(is_function(func))
  46    assert(is_list(list))
  47    [for (x=list) func(x)];
  48
  49
  50// Function: filter()
  51// Synopsis: Returns just the list items which the given function returns true for.
  52// Topics: Function Literals, Looping, Filters
  53// See Also: map(), reduce(), accumulate(), while(), for_n(), find_all()
  54// Usage:
  55//   lst = filter(func, list);
  56//   lst = filter(function (x) x>1, list);
  57// Description:
  58//   Returns all items in `list` that the function `func` returns true for.
  59//   In pseudo-code, this is effectively:
  60//   ```
  61//   function filter(func,list):
  62//       out = [];
  63//       foreach item in list:
  64//           if func(item) is true:
  65//               append item to out;
  66//       return out;
  67//   ```
  68// Arguments:
  69//   func = The function of signature `function (x)` to evaluate for each item in `list`.
  70//   list = The input list.
  71// Example:
  72//   func = function(x) x>5;
  73//   echo(filter(func, [3,4,5,6,7]));
  74//   // ECHO: [6,7]
  75function filter(func, list) =
  76    assert(is_function(func))
  77    assert(is_list(list))
  78    [for (x=list) if (func(x)) x];
  79
  80
  81// Function: reduce()
  82// Synopsis: Applies a 2-arg function cumulatively to the items of a list, returning the final result.
  83// Topics: Function Literals, Looping
  84// See Also: map(), filter(), accumulate(), while(), for_n()
  85// Usage:
  86//   res = reduce(func, list, [init]);
  87//   res = reduce(function (a,b) a+b, list, <init=);
  88// Description:
  89//   First the accumulator is set to the value in `init`.  Then, for each item in `list`, the function
  90//   in `func` is called with the accumulator and that list item, and the result is stored in the
  91//   acumulator for the next iteration.  Once all list items have been processed, the value in the
  92//   accumulator is returned.  Ie: `reduce(function (a,b) a+b, list)` is the equivalent of `sum(list)`.
  93//   In pseduo-code, this is effectively:
  94//   ```
  95//   function reduce(func, list, init=0):
  96//       x = init;
  97//       foreach item in list:
  98//           x = func(x, item);
  99//       return x;
 100//   ```
 101// Arguments:
 102//   func = The function of signature `function (x)` to evaluate for each item in `list`.
 103//   list = The input list.
 104//   init = The starting value for the accumulator.  Default: 0
 105// Example: Re-Implement sum()
 106//   x = reduce(f_add(),[3,4,5]);  // Returns: 12
 107// Example: Re-Implement product()
 108//   x = reduce(f_mul(),[3,4,5]);  // Returns: 60
 109// Example: Re-Implement all()
 110//   x = reduce(f_and(),[true,true,true]);   // Returns: true
 111//   y = reduce(f_and(),[true,false,true]);  // Returns: false
 112// Example: Re-Implement any()
 113//   x = reduce(f_or(),[false,false,false]); // Returns: false
 114//   y = reduce(f_or(),[true,false,true]);   // Returns: true
 115function reduce(func, list, init=0) =
 116    assert(is_function(func))
 117    assert(is_list(list))
 118    let(
 119        l = len(list),
 120        a = function (x,i) i<l? a(func(x,list[i]), i+1) : x
 121    ) a(init,0);
 122
 123
 124// Function: accumulate()
 125// Synopsis: Applies a 2-arg function cumulatively to the items of a list, returning a list of every result.
 126// Topics: Function Literals, Looping
 127// See Also: map(), filter(), reduce(), while(), for_n()
 128// Usage:
 129//   res = accumulate(func, list, [init]);
 130//   res = accumulate(function (a,b) a+b, list, [init=]);
 131// Description:
 132//   First the accumulator is set to the value in `init`.  Then, for each item in `list`, the function
 133//   in `func` is called with the accumulator and that list item, and the result is stored in the
 134//   acumulator for the next iteration.  That value is also appended to the output list.  Once all
 135//   list items have been processed, the list of accumulator values is returned.
 136//   In pseduo-code, this is effectively:
 137//   ```
 138//   function accumulate(func, list, init=0):
 139//       out = []
 140//       x = init;
 141//       foreach item in list:
 142//           x = func(x, item);
 143//           append x to out;
 144//       return out;
 145//   ```
 146// Arguments:
 147//   func = The function of signature `function (a,b)` to evaluate for each item in `list`.  Default: `f_add()`
 148//   list = The input list.
 149//   init = The starting value for the accumulator.  Default: 0
 150// Example: Reimplement cumsum()
 151//   echo(accumulate(function (a,b) a+b, [3,4,5],0));  // ECHO: [3,7,12]
 152// Example: Reimplement cumprod()
 153//   echo(accumulate(f_mul(),[3,4,5],1)); // ECHO: [3,12,60,360]
 154function accumulate(func, list, init=0) =
 155    assert(is_function(func))
 156    assert(is_list(list))
 157    let(
 158        l = len(list),
 159        a = function (x, i, out)
 160            i >= l ? out :
 161            let( x=func(x,list[i]) )
 162            a(x, i+1, [each out, x])
 163    ) a(init, 0, []);
 164
 165
 166// Function: while()
 167// Synopsis: While a `cond` function returns true, iteratively calls a work function, returning the final result.
 168// Topics: Function Literals, Looping, Iteration
 169// See Also: map(), filter(), reduce(), accumulate(), while(), for_n()
 170// Usage:
 171//   x = while(init, cond, func);
 172// Description:
 173//   Repeatedly calls the function literals in `cond` and `func` until the `cond` call returns false.
 174//   Both `cond` and `func` have the signature `function (i,x)`. The variable `i` is passed the iteration
 175//   number, starting with 0.  On the first iteration, the variable `x` is given by `init`.  On subsequent
 176//   iterations, `x` is given by the results of the previous call to `func`.  Returns the resulting `x` of
 177//   the final iteration.  In pseudo-code, this is effectively:
 178//   ```
 179//   function while(init, cond, func):
 180//       x = init;
 181//       i = 0;
 182//       while cond(i, x):
 183//           x = func(i, x);
 184//           i = i + 1;
 185//       return x;
 186//   ```
 187// Arguments:
 188//   init = The initial value for `x`.
 189//   cond = A function literal with signature `function (i,x)`, called to determine if the loop should continue.  Returns true if the loop should continue.
 190//   func = A function literal with signature `function (i,x)`, called on each iteration.  The returned value is passed as `x` on the next iteration.
 191// Example:
 192//   fibs = while(
 193//       init = [1,1],
 194//       cond = function (i,x) select(x,-1)<25,
 195//       func = function (i,x) concat(x, [sum(select(x,-2,-1))])
 196//   );  // Returns: [1,1,2,3,5,8,13,21]
 197function while(init, cond, func) =
 198    assert(is_function(cond))
 199    assert(is_function(func))
 200    let( a = function(x,i) cond(i,x) ? a(func(i,x),i+1) : x )
 201    a(init,0);
 202
 203
 204// Function: for_n()
 205// Synopsis: Iteratively calls a work function `n` times, returning the final result.
 206// Topics: Function Literals, Looping, Iteration
 207// See Also: map(), filter(), reduce(), accumulate(), while()
 208// Usage:
 209//   x = for_n(n, init, func);
 210// Description:
 211//   Given the function literal `func`, with the signature `function (i,x)`, repeatedly calls it `n` times.
 212//   If `n` is given as a scalar, the `i` value will traverse the range `[0:1:n-1]`, one value per call.
 213//   If `n` is given as a range, the `i` value will traverse the given range, one value per call.
 214//   The `x` value for the first  iteration is given in `init`, and in all subsequent iterations `x` will be the result of the previous call.
 215//   In pseudo-code, this is effectively:
 216//   ```
 217//   function for_n(n, init, func):
 218//       x = init;
 219//       if is_range(n):
 220//           iterate i over range n:
 221//               x = func(i,x);
 222//       else:
 223//           iterate i from 0 to n-1 by 1:
 224//               x = func(i,x);
 225//       return x;
 226//   ```
 227// Arguments:
 228//   n = The number of iterations to perform, or, if given as a range, the range to traverse.
 229//   init = The initial value to pass as `x` to the function in `func`.
 230//   func = The function literal to call, with signature `function (i,x)`.
 231// Example:
 232//   fib = function(n) for_n(
 233//       n, [],
 234//       function(i,x) x? [x[1], x[0]+x[1]] : [0,1]
 235//   )[1];
 236function for_n(n,init,func) =
 237    assert(is_finite(n))
 238    assert(is_function(func))
 239    let(
 240        n = is_num(n)? [0:1:n-1] : n,
 241        a = function(x,i) i <= n[2]? a(func(i,x), i+n[1]) : x
 242    )
 243    a(init, n[0]);
 244
 245
 246// Function: find_all()
 247// Synopsis: Returns the indices of all items in a list that a given function returns true for.
 248// Topics: Function Literals, Looping, Filters
 249// See Also: find_all(), reduce(), find_first(), binsearch()
 250// Usage:
 251//   indices = find_all(func, list);
 252//   indices = find_all(function (x) x>1, list);
 253// Description:
 254//   Returns the indices of all items in `list` that the function `func` returns true for.
 255//   In pseudo-code, this is effectively:
 256//   ```
 257//   function find_all(func,list):
 258//       out = [];
 259//       foreach item in list:
 260//           if func(item) is true:
 261//               append item index to out;
 262//       return out;
 263//   ```
 264// Arguments:
 265//   func = The function of signature `function (x)` to evaluate for each item in `list`.
 266//   list = The input list.
 267// Example:
 268//   func = function(x) x>5;
 269//   echo(find_all(func, [3,4,5,6,7]));
 270//   // ECHO: [3,4]
 271function find_all(func, list) =
 272    assert(is_function(func))
 273    assert(is_list(list))
 274    [for (indexnum=idx(list)) if (func(list[indexnum])) indexnum];
 275
 276
 277// Function: find_first()
 278// Synopsis: Returns the index of the first item in a list, after `start`, that a given function returns true for.
 279// Topics: Function Literals, Searching
 280// See Also: find_all(), filter(), binsearch(), find_all()
 281// Usage:
 282//   idx = find_first(func, list, [start=]);
 283// Description:
 284//   Finds the index of the first item in `list`, after index `start`,  which the function literal in `func` will return true for.
 285//   The signature of the function literal in `func` is `function (x)`, and it is expected to return true when the
 286//   value compares as matching.  It should return false otherwise.  If you need to find *all* matching items in the
 287//   list, you should use {{find_all()}} instead.
 288// Arguments:
 289//   func = The function literal to use to check each item in `list`.  Expects the signature `function (x)`, and a boolean return value.
 290//   list = The list to search.
 291//   ---
 292//   start = The first item to check.
 293// Example:
 294//   data = [8,5,3,7,4,2,9];
 295//   echo(find_first(f_lte(4), data));
 296//   // ECHO: 2
 297// Example:
 298//   data = [8,5,3,7,4,2,9];
 299//   echo(find_first(f_lte(4), data, start=3));
 300//   // ECHO: 4
 301function find_first(func, list, start=0) =
 302    assert(is_function(func))
 303    assert(is_list(list))
 304    assert(is_finite(start))
 305    let(
 306        listlen = len(list),
 307        _find_first = function(indexnum) (
 308            indexnum >= listlen? undef :
 309            func(list[indexnum])? indexnum :
 310            _find_first(indexnum+1)
 311        )
 312    )
 313    _find_first(start);
 314
 315
 316// Function: binsearch()
 317// Synopsis: Does a binary search of a sorted list to find the index of a given value.
 318// Topics: Function Literals, Data Structures, Searching
 319// See Also: map(), filter(), reduce(), accumulate(), hashmap(), find_all(), find_first()
 320// Usage:
 321//   idx = binsearch(key,list, [cmp]);
 322// Description:
 323//   Searches a sorted list for an entry with the given key, using a binary search strategy.
 324//   Returns the index of the matching item found.  If none found, returns undef.
 325// Arguments:
 326//   key = The key to look for.
 327//   list = The list of items to search through.
 328//   idx = If given, the index of the item sublists to use as the item key.
 329//   cmp = The comparator function literal to use.  Default: `f_cmp()`
 330// Example:
 331//   items = unique(rands(0,100,10000));
 332//   idx = binsearch(44, items);
 333// Example:
 334//   items = unique(rands(0,100,10000));
 335//   idx = binsearch(44, items, cmp=function(a,b) a-b);
 336// Example:
 337//   items = [for (i=[32:126]) [chr(i), i]];
 338//   idx = binsearch("G", items, idx=0);
 339function binsearch(key, list, idx, cmp=f_cmp()) =
 340    let(
 341        a = function(s,e)
 342            let(
 343                p = floor((s+e)/2),
 344                ikey = is_undef(idx)? list[p] : list[p][idx],
 345                c = cmp(ikey,key)
 346            )
 347            c == 0? p :
 348            c > 0? (p == s? undef : a(s, p-1)) :
 349            (p == e? undef : a(p+1, e))
 350    ) a(0,len(list)-1);
 351
 352
 353// Function: simple_hash()
 354// Synopsis: Returns an integer hash of a given value.
 355// Topics: Function Literals, Hashing, Data Structures
 356// See Also: hashmap()
 357// Usage:
 358//   hx = simple_hash(x);
 359// Description:
 360//   Given an arbitrary value, returns the integer hash value for it.
 361// Arguments:
 362//   x = The value to get the simple hash value  of.
 363// Example:
 364//   x = simple_hash("Foobar");
 365//   x = simple_hash([[10,20],[-5,3]]);
 366function simple_hash(x) =
 367    let( m = 0.5 * (sqrt(5) - 1) )
 368    is_num(x)? floor(m*x*256) :
 369    is_list(x)? let(
 370        l = len(x),
 371        a = function(i,v) i>=l? v : a(i+1, m*v + simple_hash(x[i]))
 372    ) floor(a(0,0)*4096) : let(
 373        s = str(x),
 374        l = len(s),
 375        a = function(i,v) i>=l? v : a(i+1, m*v + ord(s[i]))
 376    ) floor(a(0,0)*4096);
 377
 378
 379// Function: hashmap()
 380// Synopsis: Creates a hashmap manipulation function.
 381// Topics: Function Literals, Data Structures, Hashing
 382// See Also: simple_hash()
 383// Usage: Creating an Empty HashMap.
 384//   hm = hashmap([hashsize=]);
 385// Usage: Creating a Populated HashMap.
 386//   hm = hashmap(items=KEYVAL_LIST, [hashsize=]);
 387// Usage: Adding an Entry
 388//   hm2 = hm(key, val);
 389// Usage: Adding Multiple Entries
 390//   hm2 = hm(additems=KEYVAL_LIST);
 391// Usage: Removing an Entry
 392//   hm2 = hm(del=KEY);
 393// Usage: Fetching a Value
 394//   x = hm(key);
 395// Usage: Iterating a HashMap
 396//   for (kv=hm()) let(k=kv[0], v=kv[1]) ...
 397// Description:
 398//   This is a factory function for creating hashmap data structure functions.  You can use a hashmap
 399//   to store large amounts of [key,value] data.  At around 4000 items, this becomes faster than using
 400//   `search()` through the list.
 401// Arguments:
 402//   ---
 403//   hashsize = The number of hashtable buckets to form.
 404//   items = A list of [key,value] pairs to initialize the hashmap with.
 405// FunctionLiteral Args:
 406//   k = The key name.
 407//   v = The value to store with the key.
 408//   ---
 409//   del = If given the key of an item to delete, makes a new hashmap with that item removed.
 410//   additems = If given a list of [key,val] pairs, makes a new hashmap with the items added.
 411// Example:
 412//   hm = hashmap(items=[for (i=[0:9999]) [str("foo",i),i]]);
 413//   a = hm("foo37");  // Returns: 37
 414//   hm2 = hm("Blah", 39);  // Adds entry "Blah" with val 39.
 415//   b = hm2("Blah");  // Returns: 39
 416//   hm3 = hm2(additems=[["bar",39],["qux",21]]);  // Adds "bar" and "qux"
 417//   hm4 = hm3(del="Blah");  // Deletes entry "Blah".
 418//   for (kv = hm4()) {  // Iterates over all key/value pairs.
 419//      echo(key=kv[0], val=kv[1]);
 420//   }
 421function hashmap(hashsize=127,items,table) =
 422    let(
 423        table = !is_undef(table)? table : [for (i=[0:1:hashsize-1]) []]
 424    )
 425    items != undef? hashmap(hashsize=hashsize, table=table)(additems=items) :
 426    function(k,v,del,additems)
 427        additems!=undef? let(
 428            hashes = [for (item = additems) simple_hash(item[0]) % hashsize],
 429            grouped = list_pad(group_data(hashes, additems), hashsize, []),
 430            table = [for (i=idx(table)) concat(table[i],grouped[i])]
 431        ) hashmap(hashsize=hashsize, table=table) :
 432        del!=undef? let(
 433            bnum = simple_hash(del) % hashsize,
 434            bucket = [for (item=table[bnum]) if (item[0]!=del) item],
 435            table = [for (i=idx(table)) i==bnum? bucket : table[i]]
 436        ) hashmap(hashsize=hashsize, table=table) :
 437        k==undef && v==undef? [for (bucket=table, item=bucket) item] :
 438        let(
 439            bnum = simple_hash(k) % hashsize,
 440            bucket = table[bnum],
 441            fnd = search([k], bucket)
 442        )
 443        k!=undef && v==undef? (fnd==[]? undef : bucket[fnd[0]][1]) :
 444        let(
 445            newtable = [
 446                for (i=idx(table))
 447                i!=bnum? table[i] :
 448                !fnd? [[k,v], each bucket] :
 449                [[k,v], for (j=idx(bucket)) if (j!=fnd[0]) bucket[i]]
 450            ]
 451        ) hashmap(hashsize=hashsize, table=newtable);
 452
 453
 454
 455//////////////////////////////////////////////////////////////////////
 456// Section: Function Meta-Generators
 457
 458
 459// Function: f_1arg()
 460// Synopsis: Creates a factory for a 2-arg function literal, where you can optionally pre-fill the arg.
 461// Topics: Function Literals
 462// See Also: f_2arg(), f_3arg()
 463// Usage:
 464//   fn = f_1arg(func);
 465// Description:
 466//   Takes a function literal that accepts one argument, and returns a function
 467//   literal factory that can be used to pre-fill out that argument with a constant.
 468// Example:
 469//   f_str = f_1arg(function(a) str(a));
 470//   fn_str = f_str();   // = function(a) str(a);
 471//   fn_str3 = f_str(3); // = function() str(3);
 472function f_1arg(target_func) =
 473    function(a)
 474        a==undef? function(x) target_func(x) :
 475        function() target_func(a);
 476
 477
 478// Function: f_2arg()
 479// Synopsis: Creates a factory for a 2-arg function literal, where you can optionally pre-fill the args.
 480// Topics: Function Literals
 481// See Also: f_1arg(), f_3arg()
 482// Usage:
 483//   fn = f_2arg(target_func);
 484// Description:
 485//   Takes a function literal that accepts two arguments, and returns a function
 486//   literal factory that can be used to pre-fill out one or both of those arguments
 487//   with a constant.
 488// Example:
 489//   f_lt = f_2arg(function(a,b) a<b);
 490//   fn_lt = f_lt();      // = function(a,b) a<b;
 491//   fn_3lt = f_lt(3);    // = function(b) 3<b;
 492//   fn_3lt = f_lt(a=3);  // = function(b) 3<b;
 493//   fn_lt3 = f_lt(b=3);  // = function(a) a<3;
 494//   fn_3lt4 = f_lt(3,4); // = function() 3<4;
 495function f_2arg(target_func) =
 496    function(a,b)
 497        a==undef && b==undef? function(x,y) target_func(x,y) :
 498        a==undef? function(x) target_func(x,b) :
 499        b==undef? function(x) target_func(a,x) :
 500        function() target_func(a,b);
 501
 502
 503// Function: f_2arg_simple()
 504// Synopsis: Creates a factory for a 2-arg function literal, where you can optionally pre-fill the args.
 505// Topics: Function Literals
 506// See Also: f_1arg(), f_3arg()
 507// Usage:
 508//   fn = f_2arg_simple(target_func);
 509// Description:
 510//   Takes a function literal that accepts two arguments, and returns a function
 511//   literal factory that can be used to pre-fill out one or both of those arguments
 512//   with a constant.  When given a single argument, fills out the segond function
 513//   argument with a constant.
 514// Example:
 515//   f_lt = f_2arg_simple(function(a,b) a<b);
 516//   fn_lt = f_lt();       // = function(a,b) a<b;
 517//   fn_lt3 = f_lt(3);     // = function(a) a<3;
 518//   fn_3lt4 = f_lt(3,4);  // = function() 3<4;
 519function f_2arg_simple(target_func) =
 520    function(a,b)
 521        a==undef && b==undef? function(x,y) target_func(x,y) :
 522        b==undef? function(x) target_func(x,a) :
 523        function() target_func(a,b);
 524
 525
 526// Function: f_3arg()
 527// Synopsis: Creates a factory for a 3-arg function literal, where you can optionally pre-fill the args.
 528// Topics: Function Literals
 529// See Also: f_1arg(), f_2arg()
 530// Usage:
 531//   fn = f_3arg(target_func);
 532// Description:
 533//   Takes a function literal that accepts three arguments, and returns a function
 534//   literal factory that can be used to pre-fill out some or all of those arguments
 535//   with a constant.
 536// Example:
 537//   p1 = [10,4]; p2 = [3,7];
 538//   f_va = f_3arg(function(a,b,c) vector_angle(a,b,c));
 539//   fn_va = f_va();       // = function(a,b,c) vector_angle(a,b,c);
 540//   fn_va2 = f_lt(c=p1);  // = function(a,b) vector_angle(a,b,p1);
 541//   fn_va3 = f_lt(a=p2);  // = function(a,c) vector_angle(a,p2,c);
 542//   fn_va4 = f_lt(a=p1,c=p2); // = function() vector_angle(p1,b,p2);
 543function f_3arg(target_func) =
 544    function(a,b,c)
 545        a==undef && b==undef && c==undef? function(x,y,z) target_func(x,y,z) :
 546        a==undef && b==undef? function(x,y) target_func(x,y,c) :
 547        a==undef && c==undef? function(x,y) target_func(x,b,y) :
 548        b==undef && c==undef? function(x,y) target_func(a,x,y) :
 549        a==undef? function(x) target_func(x,b,c) :
 550        b==undef? function(x) target_func(a,x,c) :
 551        c==undef? function(x) target_func(a,b,x) :
 552        function() target_func(a,b,c);
 553
 554
 555// Function: ival()
 556// Synopsis: Generates a function with signature `(i,x)` that calls `func(i)`
 557// Topics: Function Literals
 558// See Also: f_1arg(), f_2arg(), f_3arg(), ival(), xval()
 559// Usage:
 560//   newfunc = ival(func);
 561// Description:
 562//   Wraps a single-argument function literal so that it can take two arguments,
 563//   passing the first argument along to the wrapped function.
 564// Arguments:
 565//   target_func = The function of signature (x) to wrap.
 566// FunctionLiteral Args:
 567//   a = The argument that will be passed through.
 568//   b = The argumen that will be discarded.
 569// Example:
 570//   x = while(0, ival(f_lt(5)), xval(f_add(1)));
 571function ival(target_func) = function(a,b) target_func(a);
 572
 573
 574// Function: xval()
 575// Synopsis: Generates a function with signature `(i,x)` that calls `func(x)`
 576// Topics: Function Literals
 577// See Also: f_1arg(), f_2arg(), f_3arg(), ival(), xval()
 578// Usage:
 579//   newfunc = xval(func);
 580// Description:
 581//   Wraps a single-argument function literal so that it can take two arguments,
 582//   passing the first argument along to the wrapped function.
 583// Arguments:
 584//   target_func = The function of signature (x) to wrap.
 585// FunctionLiteral Args:
 586//   a = The argument that will be passed through.
 587//   b = The argumen that will be discarded.
 588// Example:
 589//   x = while(0, ival(f_lt(5)), xval(f_add(1)));
 590function xval(target_func) = function(a,b) target_func(b);
 591
 592
 593
 594//////////////////////////////////////////////////////////////////////
 595// Section: Comparator Generators
 596
 597
 598// Function: f_cmp()
 599// Synopsis: Returns a function to compare values.
 600// Topics: Function Literals, Comparators
 601// See Also: f_cmp(), f_gt(), f_lt(), f_gte(), f_lte(), f_eq(), f_neq(), f_approx(), f_napprox()
 602// Usage:
 603//   fn = f_cmp();
 604//   fn = f_cmp(b);
 605//   fn = f_cmp(a,b);
 606// Description:
 607//   A factory that generates function literals that compare `a` and `b`, where one or
 608//   both arguments can be replaced with constants.  If `a` and `b` are equal, the function
 609//   literal will return 0.  If a<b then -1 is returned.  If a>b then 1 is returned.
 610// Example:
 611//   fn_cmp = f_cmp();       // = function(a,b) a==b?0: a>b?1: -1;
 612//   fn_cmp3 = f_cmp(3);     // = function(a) a==3?0: a>3?1: -1;
 613//   fn_3cmp4 = f_cmp(3,4);  // = function() 3==4?0: 3>4?1: -1;
 614function f_cmp(a,b) = f_2arg_simple(function (a,b) a==b?0: a>b?1: -1)(a,b);
 615
 616
 617// Function: f_gt()
 618// Synopsis: Returns a function to compare if `a` is greater than `b`.
 619// Topics: Function Literals, Comparators
 620// See Also: f_cmp(), f_gt(), f_lt(), f_gte(), f_lte(), f_eq(), f_neq(), f_approx(), f_napprox()
 621// Usage:
 622//   fn = f_gt();
 623//   fn = f_gt(b);
 624//   fn = f_gt(a,b);
 625// Description:
 626//   A factory that generates function literals based on `a > b`, where one
 627//   or both of the arguments can be replaced with constants.
 628// Example:
 629//   fn_gt = f_gt();       // = function(a,b) a>b;
 630//   fn_gt3 = f_gt(3);     // = function(a) a>3;
 631//   fn_3gt4 = f_gt(3,4);  // = function() 3>4;
 632function f_gt(a,b) = f_2arg_simple(function (a,b) a>b)(a,b);
 633
 634
 635// Function: f_lt()
 636// Synopsis: Returns a function to compare if `a` is less than `b`.
 637// Topics: Function Literals, Comparators
 638// See Also: f_cmp(), f_gt(), f_lt(), f_gte(), f_lte(), f_eq(), f_neq(), f_approx(), f_napprox()
 639// Usage:
 640//   fn = f_lt();
 641//   fn = f_lt(b);
 642//   fn = f_lt(a,b);
 643// Description:
 644//   A factory that generates function literals based on `a < b`, where one
 645//   or both of the arguments can be replaced with constants.
 646// Example:
 647//   fn_lt = f_lt();       // = function(a,b) a<b;
 648//   fn_lt3 = f_lt(3);     // = function(a) a<3;
 649//   fn_3lt4 = f_lt(3,4);  // = function() 3<4;
 650function f_lt(a,b) = f_2arg_simple(function (a,b) a<b)(a,b);
 651
 652
 653// Function: f_gte()
 654// Synopsis: Returns a function to compare if `a` is greater than or equal to `b`.
 655// Topics: Function Literals, Comparators
 656// See Also: f_cmp(), f_gt(), f_lt(), f_gte(), f_lte(), f_eq(), f_neq(), f_approx(), f_napprox()
 657// Usage:
 658//   fn = f_gte();
 659//   fn = f_gte(b);
 660//   fn = f_gte(a,b);
 661// Description:
 662//   A factory that generates function literals based on `a >= b`, where one
 663//   or both of the arguments can be replaced with constants.
 664// Example:
 665//   fn_gte = f_gte();       // = function(a,b) a>=b;
 666//   fn_gte3 = f_gte(3);     // = function(a) a>=3;
 667//   fn_3gte4 = f_gte(3,4);  // = function() 3>=4;
 668function f_gte(a,b) = f_2arg_simple(function (a,b) a>=b)(a,b);
 669
 670
 671// Function: f_lte()
 672// Synopsis: Returns a function to compare if `a` is less than or equal to `b`.
 673// Topics: Function Literals, Comparators
 674// See Also: f_cmp(), f_gt(), f_lt(), f_gte(), f_lte(), f_eq(), f_neq(), f_approx(), f_napprox()
 675// Usage:
 676//   fn = f_lte();
 677//   fn = f_lte(b);
 678//   fn = f_lte(a,b);
 679// Description:
 680//   A factory that generates function literals based on `a <= b`, where
 681//   one or both arguments can be replaced with constants.
 682// Example:
 683//   fn_lte = f_lte();       // = function(a,b) a<=b;
 684//   fn_lte3 = f_lte(3);     // = function(a) a<=3;
 685//   fn_3lte4 = f_lte(3,4);  // = function() 3<=4;
 686function f_lte(a,b) = f_2arg_simple(function (a,b) a<=b)(a,b);
 687
 688
 689// Function: f_eq()
 690// Synopsis: Returns a function to compare if `a` is exactly equal to `b`.
 691// Topics: Function Literals, Comparators
 692// See Also: f_cmp(), f_gt(), f_lt(), f_gte(), f_lte(), f_eq(), f_neq(), f_approx(), f_napprox()
 693// Usage:
 694//   fn = f_eq();
 695//   fn = f_eq(b);
 696//   fn = f_eq(a,b);
 697// Description:
 698//   A factory that generates function literals based on `a == b`, where
 699//   one or both arguments can be replaced with constants.
 700// Example:
 701//   fn_eq = f_eq();       // = function(a,b) a==b;
 702//   fn_eq3 = f_eq(3);     // = function(a) a==3;
 703//   fn_3eq4 = f_eq(3,4);  // = function() 3==4;
 704function f_eq(a,b) = f_2arg_simple(function (a,b) a==b)(a,b);
 705
 706
 707// Function: f_neq()
 708// Synopsis: Returns a function to compare if `a` is not exactly equal to `b`.
 709// Topics: Function Literals, Comparators
 710// See Also: f_cmp(), f_gt(), f_lt(), f_gte(), f_lte(), f_eq(), f_neq(), f_approx(), f_napprox()
 711// Usage:
 712//   fn = f_neq();
 713//   fn = f_neq(b);
 714//   fn = f_neq(a,b);
 715// Description:
 716//   A factory that generates function literals based on `a != b`, where
 717//   one or both arguments can be replaced with constants.
 718// Example:
 719//   fn_neq = f_neq();       // = function(a,b) a!=b;
 720//   fn_neq3 = f_neq(3);     // = function(a) a!=3;
 721//   fn_3neq4 = f_neq(3,4);  // = function() 3!=4;
 722function f_neq(a,b) = f_2arg_simple(function (a,b) a!=b)(a,b);
 723
 724
 725// Function: f_approx()
 726// Synopsis: Returns a function to compare if `a` is approximately equal to `b`.
 727// Topics: Function Literals, Comparators
 728// See Also: f_cmp(), f_gt(), f_lt(), f_gte(), f_lte(), f_eq(), f_neq(), f_approx(), f_napprox()
 729// Usage:
 730//   fn = f_approx();
 731//   fn = f_approx(b);
 732//   fn = f_approx(a,b);
 733// Description:
 734//   A factory that generates function literals based on `approx(a,b)`, where
 735//   one or both arguments can be replaced with constants.
 736// Example:
 737//   fn_approx = f_approx();       // = function(a,b) approx(a,b);
 738//   fn_approx3 = f_approx(3);     // = function(a) approx(a,3);
 739//   fn_3approx4 = f_approx(3,4);  // = function() approx(3,4);
 740function f_approx(a,b) = f_2arg_simple(function (a,b) approx(a,b))(a,b);
 741
 742
 743// Function: f_napprox()
 744// Synopsis: Returns a function to compare if `a` is not approximately equal to `b`.
 745// Topics: Function Literals, Comparators
 746// See Also: f_cmp(), f_gt(), f_lt(), f_gte(), f_lte(), f_eq(), f_neq(), f_approx(), f_napprox()
 747// Usage:
 748//   fn = f_napprox();
 749//   fn = f_napprox(b);
 750//   fn = f_napprox(a,b);
 751// Description:
 752//   A factory that generates function literals based on `!approx(a,b)`, where
 753//   one or both arguments can be replaced with constants.
 754// Example:
 755//   fn_napprox = f_napprox();       // = function(a,b) napprox(a,b);
 756//   fn_napprox3 = f_napprox(3);     // = function(a) napprox(a,3);
 757//   fn_3napprox4 = f_napprox(3,4);  // = function() napprox(3,4);
 758function f_napprox(a,b) = f_2arg_simple(function (a,b) !approx(a,b))(a,b);
 759
 760
 761
 762//////////////////////////////////////////////////////////////////////
 763// Section: Logic Operators
 764
 765
 766// Function: f_or()
 767// Synopsis: Returns a function to check if either `a` or `b` is true.
 768// Topics: Function Literals, Logic, Boolean Operations
 769// See Also: f_or(), f_and(), f_nor(), f_nand(), f_xor(), f_not()
 770// Usage:
 771//   fn = f_or();
 772//   fn = f_or(a=);
 773//   fn = f_or(b=);
 774//   fn = f_or(a=,b=);
 775// Description:
 776//   A factory that generates function literals based on `a || b`, where
 777//   either or both of the `a` or `b` arguments can be replaced with constants.
 778// Arguments:
 779//   a = If given, replaces the first argument.
 780//   b = If given, replaces the second argument.
 781function f_or(a,b) = f_2arg(function(a,b) (a || b))(a,b);
 782
 783
 784// Function: f_and()
 785// Synopsis: Returns a function to check if both `a` and `b` are true.
 786// Topics: Function Literals, Logic, Boolean Operations
 787// See Also: f_or(), f_and(), f_nor(), f_nand(), f_xor(), f_not()
 788// Usage:
 789//   fn = f_and();
 790//   fn = f_and(a=);
 791//   fn = f_and(b=);
 792//   fn = f_and(a=,b=);
 793// Description:
 794//   A factory that generates function literals based on `a && b`, where
 795//   either or both of the `a` or `b` arguments can be replaced with constants.
 796// Arguments:
 797//   a = If given, replaces the first argument.
 798//   b = If given, replaces the second argument.
 799function f_and(a,b) = f_2arg(function(a,b) (a && b))(a,b);
 800
 801
 802// Function: f_nor()
 803// Synopsis: Returns a function to check if neither `a` nor `b` are true.
 804// Topics: Function Literals, Logic, Boolean Operations
 805// See Also: f_or(), f_and(), f_nor(), f_nand(), f_xor(), f_not()
 806// Usage:
 807//   fn = f_nor();
 808//   fn = f_nor(a=);
 809//   fn = f_nor(b=);
 810//   fn = f_nor(a=,b=);
 811// Description:
 812//   A factory that generates function literals based on `!(a || b)`, where
 813//   either or both of the `a` or `b` arguments can be replaced with constants.
 814// Arguments:
 815//   a = If given, replaces the first argument.
 816//   b = If given, replaces the second argument.
 817function f_nor(a,b) = f_2arg(function(a,b) !(a || b))(a,b);
 818
 819
 820// Function: f_nand()
 821// Synopsis: Returns a function to check if `a` and `b` are not both true.
 822// Topics: Function Literals, Logic, Boolean Operations
 823// See Also: f_or(), f_and(), f_nor(), f_nand(), f_xor(), f_not()
 824// Usage:
 825//   fn = f_nand();
 826//   fn = f_nand(a=);
 827//   fn = f_nand(b=);
 828//   fn = f_nand(a=,b=);
 829// Description:
 830//   A factory that generates function literals based on `!(a && b)`, where
 831//   either or both of the `a` or `b` arguments can be replaced with constants.
 832// Arguments:
 833//   a = If given, replaces the first argument.
 834//   b = If given, replaces the second argument.
 835function f_nand(a,b) = f_2arg(function(a,b) !(a && b))(a,b);
 836
 837
 838// Function: f_xor()
 839// Synopsis: Returns a function to check if either `a` or `b`, but not both, are true.
 840// Topics: Function Literals, Logic, Boolean Operations
 841// See Also: f_or(), f_and(), f_nor(), f_nand(), f_xor(), f_not()
 842// Usage:
 843//   fn = f_xor();
 844//   fn = f_xor(a=);
 845//   fn = f_xor(b);
 846//   fn = f_xor(a=,b=);
 847// Description:
 848//   A factory that generates function literals based on `(!a && b) || (a && !b)`, where
 849//   either or both of the `a` or `b` arguments can be replaced with constants.
 850// Arguments:
 851//   a = If given, replaces the first argument.
 852//   b = If given, replaces the second argument.
 853function f_xor(a,b) = f_2arg(function(a,b) (!a && b) || (a && !b))(a,b);
 854
 855
 856// Function: f_not()
 857// Synopsis: Returns a function to check if `a` is not true.
 858// Topics: Function Literals, Logic, Boolean Operations
 859// See Also: f_or(), f_and(), f_nor(), f_nand(), f_xor(), f_not()
 860// Usage:
 861//   fn = f_not();
 862//   fn = f_not(a);
 863// Description:
 864//   A factory that generates function literals based on `!a`, where the `a`
 865//   argument can be replaced with a constant.
 866// Arguments:
 867//   a = If given, replaces the argument.
 868function f_not(a) = f_1arg(function(a) !a)(a);
 869
 870
 871// Function: f_even()
 872// Synopsis: Returns a function to check if `a` is an even number.
 873// Topics: Function Literals, Math Operators
 874// See Also: f_even(), f_odd()
 875// Usage:
 876//   fn = f_even();
 877//   fn = f_even(a);
 878// Description:
 879//   A factory that generates function literals based on `a % 2 == 0`, where the `a`
 880//   argument can optionally be replaced with a constant.
 881// Arguments:
 882//   a = If given, replaces the argument.
 883// Example:
 884//   l2 = filter(f_even(), [3,4,5,6,7,8]);  // Returns: [4,6,8]
 885function f_even(a) = f_1arg(function(a) a % 2 == 0)(a);
 886
 887
 888// Function: f_odd()
 889// Synopsis: Returns a function to check if `a` is an odd number.
 890// Topics: Function Literals, Math Operators
 891// See Also: f_even(), f_odd()
 892// Usage:
 893//   fn = f_odd();
 894//   fn = f_odd(a);
 895// Description:
 896//   A factory that generates function literals based on `a % 2 != 0`, where the `a`
 897//   argument can optionally be replaced with a constant.
 898// Arguments:
 899//   a = If given, replaces the argument.
 900// Example:
 901//   l2 = filter(f_odd(), [3,4,5,6,7,8]);  // Returns: [3,5,7]
 902function f_odd(a) = f_1arg(function(a) a % 2 != 0)(a);
 903
 904
 905
 906//////////////////////////////////////////////////////////////////////
 907// Section: Math Operators
 908
 909
 910// Function: f_add()
 911// Synopsis: Returns a function to add `a` and `b`.
 912// Topics: Function Literals, Math Operators
 913// See Also: f_add(), f_sub(), f_mul(), f_div(), f_mod(), f_pow(), f_neg()
 914// Usage:
 915//   fn = f_add();
 916//   fn = f_add(a=);
 917//   fn = f_add(b);
 918//   fn = f_add(a=,b=);
 919// Description:
 920//   A factory that generates function literals based on `a + b`, where either
 921//   or both of the `a` or `b` arguments can be replaced with constants.
 922// Arguments:
 923//   a = If given, replaces the first argument.
 924//   b = If given, replaces the second argument.
 925function f_add(a,b) = f_2arg(function(a,b) a + b)(a,b);
 926
 927
 928// Function: f_sub()
 929// Synopsis: Returns a function to subtract `a` from `b`.
 930// Topics: Function Literals, Math Operators
 931// See Also: f_add(), f_sub(), f_mul(), f_div(), f_mod(), f_pow(), f_neg()
 932// Usage:
 933//   fn = f_sub();
 934//   fn = f_sub(a=);
 935//   fn = f_sub(b);
 936//   fn = f_sub(a=,b=);
 937// Description:
 938//   A factory that generates function literals based on `a - b`, where either
 939//   or both of the `a` or `b` arguments can be replaced with constants.
 940// Arguments:
 941//   a = If given, replaces the first argument.
 942//   b = If given, replaces the second argument.
 943function f_sub(a,b) = f_2arg(function(a,b) a - b)(a,b);
 944
 945
 946// Function: f_mul()
 947// Synopsis: Returns a function to multiply `a` by `b`.
 948// Topics: Function Literals, Math Operators
 949// See Also: f_add(), f_sub(), f_mul(), f_div(), f_mod(), f_pow(), f_neg()
 950// Usage:
 951//   fn = f_mul();
 952//   fn = f_mul(a=);
 953//   fn = f_mul(b);
 954//   fn = f_mul(a=,b=);
 955// Description:
 956//   A factory that generates function literals based on `a * b`, where either
 957//   or both of the `a` or `b` arguments can be replaced with constants.
 958// Arguments:
 959//   a = If given, replaces the first argument.
 960//   b = If given, replaces the second argument.
 961function f_mul(a,b) = f_2arg(function(a,b) a * b)(a,b);
 962
 963
 964// Function: f_div()
 965// Synopsis: Returns a function to divide `a` by `b`.
 966// Topics: Function Literals, Math Operators
 967// See Also: f_add(), f_sub(), f_mul(), f_div(), f_mod(), f_pow(), f_neg()
 968// Usage:
 969//   fn = f_div();
 970//   fn = f_div(a=);
 971//   fn = f_div(b);
 972//   fn = f_div(a=,b=);
 973// Description:
 974//   A factory that generates function literals based on `a / b`, where either
 975//   or both of the `a` or `b` arguments can be replaced with constants.
 976// Arguments:
 977//   a = If given, replaces the first argument.
 978//   b = If given, replaces the second argument.
 979function f_div(a,b) = f_2arg(function(a,b) a / b)(a,b);
 980
 981
 982// Function: f_mod()
 983// Synopsis: Returns a function to calculate the modulo of `a` divided by `b`.
 984// Topics: Function Literals, Math Operators
 985// See Also: f_add(), f_sub(), f_mul(), f_div(), f_mod(), f_pow(), f_neg()
 986// Usage:
 987//   fn = f_mod();
 988//   fn = f_mod(a=);
 989//   fn = f_mod(b);
 990//   fn = f_mod(a=,b=);
 991// Description:
 992//   A factory that generates function literals based on `a % b`, where either
 993//   or both of the `a` or `b` arguments can be replaced with constants.
 994// Arguments:
 995//   a = If given, replaces the first argument.
 996//   b = If given, replaces the second argument.
 997function f_mod(a,b) = f_2arg(function(a,b) a % b)(a,b);
 998
 999
1000// Function: f_pow()
1001// Synopsis: Returns a function to calculate `a` to the power of `b`.
1002// Topics: Function Literals, Math Operators
1003// See Also: f_add(), f_sub(), f_mul(), f_div(), f_mod(), f_pow(), f_neg()
1004// Usage:
1005//   fn = f_pow();
1006//   fn = f_pow(a=);
1007//   fn = f_pow(b);
1008//   fn = f_pow(a=,b=);
1009// Description:
1010//   A factory that generates function literals based on `pow(a,b)`, where either
1011//   or both of the `a` or `b` arguments can be replaced with constants.
1012// Arguments:
1013//   a = If given, replaces the first argument.
1014//   b = If given, replaces the second argument.
1015function f_pow(a,b) = f_2arg(function(a,b) pow(a,b))(a,b);
1016
1017
1018// Function: f_neg()
1019// Synopsis: Returns a function to calculate `-a`
1020// Topics: Function Literals, Math Operators
1021// See Also: f_add(), f_sub(), f_mul(), f_div(), f_mod(), f_pow(), f_neg()
1022// Usage:
1023//   fn = f_neg();
1024//   fn = f_neg(a);
1025// Description:
1026//   A factory that generates function literals based on `-a`, where the `a`
1027//   argument can optionally be replaced with a constant.
1028// Arguments:
1029//   a = If given, replaces the argument.
1030function f_neg(a) = f_1arg(function(a) -a)(a);
1031
1032
1033
1034//////////////////////////////////////////////////////////////////////
1035// Section: Min/Max Operators
1036
1037
1038// Function: f_min()
1039// Synopsis: Returns a function to calculate the minimum value of a list.
1040// Topics: Function Literals, Math Operators
1041// See Also: f_min(), f_max(), f_min2(), f_max2(), f_min3(), f_max3()
1042// Usage:
1043//   fn = f_min();
1044//   fn = f_min(a);
1045// Description:
1046//   A factory that generates function literals based on `min(a)`, where the `a`
1047//   argument can optionally be replaced with a constant.
1048// Arguments:
1049//   a = If given, replaces the argument.
1050function f_min(a) = f_1arg(function(a) min(a))(a);
1051
1052
1053// Function: f_max()
1054// Synopsis: Returns a function to calculate the maximum value of a list.
1055// Topics: Function Literals, Math Operators
1056// See Also: f_min(), f_max(), f_min2(), f_max2(), f_min3(), f_max3()
1057// Usage:
1058//   fn = f_max();
1059//   fn = f_max(a);
1060// Description:
1061//   A factory that generates function literals based on `max(a)`, where the `a`
1062//   argument can optionally be replaced with a constant.
1063// Arguments:
1064//   a = If given, replaces the argument.
1065function f_max(a) = f_1arg(function(a) max(a))(a);
1066
1067
1068// Function: f_min2()
1069// Synopsis: Returns a function to calculate the minimum of two values.
1070// Topics: Function Literals, Math Operators
1071// See Also: f_min(), f_max(), f_min2(), f_max2(), f_min3(), f_max3()
1072// Usage:
1073//   fn = f_min2();
1074//   fn = f_min2(a=);
1075//   fn = f_min2(b);
1076//   fn = f_min2(a=,b=);
1077// Description:
1078//   A factory that generates function literals based on `min(a,b)`, where either
1079//   or both of the `a` or `b` arguments can be replaced with constants.
1080// Arguments:
1081//   a = If given, replaces the first argument.
1082//   b = If given, replaces the second argument.
1083function f_min2(a,b) = f_2arg(function(a,b) min(a,b))(a,b);
1084
1085
1086// Function: f_max2()
1087// Synopsis: Returns a function to calculate the maximum of two values.
1088// Topics: Function Literals, Math Operators
1089// See Also: f_min(), f_max(), f_min2(), f_max2(), f_min3(), f_max3()
1090// Usage:
1091//   fn = f_max2();
1092//   fn = f_max2(a=);
1093//   fn = f_max2(b);
1094//   fn = f_max2(a=,b=);
1095// Description:
1096//   A factory that generates function literals based on `max(a,b)`, where either
1097//   or both of the `a` or `b` arguments can be replaced with constants.
1098// Arguments:
1099//   a = If given, replaces the first argument.
1100//   b = If given, replaces the second argument.
1101function f_max2(a,b) = f_2arg(function(a,b) max(a,b))(a,b);
1102
1103
1104// Function: f_min3()
1105// Synopsis: Returns a function to calculate the minimum of three values.
1106// Topics: Function Literals, Math Operators
1107// See Also: f_min(), f_max(), f_min2(), f_max2(), f_min3(), f_max3()
1108// Usage:
1109//   fn = f_min3();
1110//   fn = f_min3(a=);
1111//   fn = f_min3(b=);
1112//   fn = f_min3(c=);
1113//   fn = f_min3(a=,b=);
1114//   fn = f_min3(b=,c=);
1115//   fn = f_min3(a=,c=);
1116//   fn = f_min3(a=,b=,c=);
1117// Description:
1118//   A factory that generates function literals based on `min(a,b,c)`, where any
1119//   or all of the `a`, `b`, or`c` arguments can be replaced with constants.
1120// Arguments:
1121//   a = If given, replaces the first argument.
1122//   b = If given, replaces the second argument.
1123//   c = If given, replaces the third argument.
1124function f_min3(a,b,c) = f_3arg(function(a,b,c) min(a,b,c))(a,b,c);
1125
1126
1127// Function: f_max3()
1128// Synopsis: Returns a function to calculate the maximum of three values.
1129// Topics: Function Literals, Math Operators
1130// See Also: f_min(), f_max(), f_min2(), f_max2(), f_min3(), f_max3()
1131// Usage:
1132//   fn = f_max3();
1133//   fn = f_max3(a=);
1134//   fn = f_max3(b=);
1135//   fn = f_max3(c=);
1136//   fn = f_max3(a=,b=);
1137//   fn = f_max3(b=,c=);
1138//   fn = f_max3(a=,c=);
1139//   fn = f_max3(a=,b=,c=);
1140// Description:
1141//   A factory that generates function literals based on `min(a,b,c)`, where any
1142//   or all of the `a`, `b`, or`c` arguments can be replaced with constants.
1143// Arguments:
1144//   a = If given, replaces the first argument.
1145//   b = If given, replaces the second argument.
1146//   c = If given, replaces the third argument.
1147function f_max3(a,b,c) = f_3arg(function(a,b,c) max(a,b,c))(a,b,c);
1148
1149
1150
1151//////////////////////////////////////////////////////////////////////
1152// Section: Trigonometry Operators
1153
1154
1155// Function: f_sin()
1156// Synopsis: Returns a function to calculate the sine of a value.
1157// Topics: Function Literals, Math Operators
1158// See Also: f_sin(), f_cos(), f_tan(), f_asin(), f_acos(), f_atan(), f_atan2()
1159// Usage:
1160//   fn = f_sin();
1161//   fn = f_sin(a);
1162// Description:
1163//   A factory that generates function literals based on `sin(a)`, where the `a`
1164//   argument can optionally be replaced with a constant.
1165// Arguments:
1166//   a = If given, replaces the argument.
1167function f_sin(a)  = f_1arg(function(a) sin(a))(a);
1168
1169
1170// Function: f_cos()
1171// Synopsis: Returns a function to calculate the cosine of a value.
1172// Topics: Function Literals, Math Operators
1173// See Also: f_sin(), f_cos(), f_tan(), f_asin(), f_acos(), f_atan(), f_atan2()
1174// Usage:
1175//   fn = f_cos();
1176//   fn = f_cos(a);
1177// Description:
1178//   A factory that generates function literals based on `cos(a)`, where the `a`
1179//   argument can optionally be replaced with a constant.
1180// Arguments:
1181//   a = If given, replaces the argument.
1182function f_cos(a)  = f_1arg(function(a) cos(a))(a);
1183
1184
1185// Function: f_tan()
1186// Synopsis: Returns a function to calculate the tangent of a value.
1187// Topics: Function Literals, Math Operators
1188// See Also: f_sin(), f_cos(), f_tan(), f_asin(), f_acos(), f_atan(), f_atan2()
1189// Usage:
1190//   fn = f_tan();
1191//   fn = f_tan(a);
1192// Description:
1193//   A factory that generates function literals based on `tan(a)`, where the `a`
1194//   argument can optionally be replaced with a constant.
1195// Arguments:
1196//   a = If given, replaces the argument.
1197function f_tan(a)  = f_1arg(function(a) tan(a))(a);
1198
1199
1200// Function: f_asin()
1201// Synopsis: Returns a function to calculate the arcsine of a value.
1202// Topics: Function Literals, Math Operators
1203// See Also: f_sin(), f_cos(), f_tan(), f_asin(), f_acos(), f_atan(), f_atan2()
1204// Usage:
1205//   fn = f_asin();
1206//   fn = f_asin(a);
1207// Description:
1208//   A factory that generates function literals based on `asin(a)`, where the `a`
1209//   argument can optionally be replaced with a constant.
1210// Arguments:
1211//   a = If given, replaces the argument.
1212function f_asin(a) = f_1arg(function(a) asin(a))(a);
1213
1214
1215// Function: f_acos()
1216// Synopsis: Returns a function to calculate the arccosine of a value.
1217// Topics: Function Literals, Math Operators
1218// See Also: f_sin(), f_cos(), f_tan(), f_asin(), f_acos(), f_atan(), f_atan2()
1219// Usage:
1220//   fn = f_acos();
1221//   fn = f_acos(a);
1222// Description:
1223//   A factory that generates function literals based on `acos(a)`, where the `a`
1224//   argument can optionally be replaced with a constant.
1225// Arguments:
1226//   a = If given, replaces the argument.
1227function f_acos(a) = f_1arg(function(a) acos(a))(a);
1228
1229
1230// Function: f_atan()
1231// Synopsis: Returns a function to calculate the arctangent of a value.
1232// Topics: Function Literals, Math Operators
1233// See Also: f_sin(), f_cos(), f_tan(), f_asin(), f_acos(), f_atan(), f_atan2()
1234// Usage:
1235//   fn = f_atan();
1236//   fn = f_atan(a);
1237// Description:
1238//   A factory that generates function literals based on `atan(a)`, where the `a`
1239//   argument can optionally be replaced with a constant.
1240// Arguments:
1241//   a = If given, replaces the argument.
1242function f_atan(a) = f_1arg(function(a) atan(a))(a);
1243
1244
1245// Function: f_atan2()
1246// Synopsis: Returns a function to calculate the arctangent of `y` and `x`
1247// Topics: Function Literals, Math Operators
1248// See Also: f_sin(), f_cos(), f_tan(), f_asin(), f_acos(), f_atan(), f_atan2()
1249// Usage:
1250//   fn = f_atan2();
1251//   fn = f_atan2(a=);
1252//   fn = f_atan2(b);
1253//   fn = f_atan2(a=,b=);
1254// Description:
1255//   A factory that generates function literals based on `atan2(a,b)`, where either
1256//   or both of the `a` or `b` arguments can be replaced with constants.
1257// Arguments:
1258//   a = If given, replaces the first argument.
1259//   b = If given, replaces the second argument.
1260function f_atan2(a,b) = f_2arg(function(a,b) atan2(a,b))(a,b);
1261
1262
1263
1264//////////////////////////////////////////////////////////////////////
1265// Section: String Operators
1266
1267
1268// Function: f_len()
1269// Synopsis: Returns a function to calculate the length of a string or list.
1270// Topics: Function Literals, String Operators
1271// See Also: f_len(), f_chr(), f_ord(), f_str(), f_str2(), f_str3()
1272// Usage:
1273//   fn = f_len();
1274//   fn = f_len(a);
1275// Description:
1276//   A factory that generates function literals based on `len(a)`, where the `a`
1277//   argument can optionally be replaced with a constant.
1278// Arguments:
1279//   a = If given, replaces the argument.
1280function f_len(a) = f_1arg(function(a) len(a))(a);
1281
1282
1283// Function: f_chr()
1284// Synopsis: Returns a function to get a string character from its ordinal number.
1285// Topics: Function Literals, String Operators
1286// See Also: f_len(), f_chr(), f_ord(), f_str(), f_str2(), f_str3()
1287// Usage:
1288//   fn = f_chr();
1289//   fn = f_chr(a);
1290// Description:
1291//   A factory that generates function literals based on `chr(a)`, where the `a`
1292//   argument can optionally be replaced with a constant.
1293// Arguments:
1294//   a = If given, replaces the argument.
1295function f_chr(a) = f_1arg(function(a) chr(a))(a);
1296
1297
1298// Function: f_ord()
1299// Synopsis: Returns a function to get the ordinal number of a string character.
1300// Topics: Function Literals, String Operators
1301// See Also: f_len(), f_chr(), f_ord(), f_str(), f_str2(), f_str3()
1302// Usage:
1303//   fn = f_ord();
1304//   fn = f_ord(a);
1305// Description:
1306//   A factory that generates function literals based on `ord(a)`, where the `a`
1307//   argument can optionally be replaced with a constant.
1308// Arguments:
1309//   a = If given, replaces the argument.
1310function f_ord(a) = f_1arg(function(a) ord(a))(a);
1311
1312
1313// Function: f_str()
1314// Synopsis: Returns a function to get the string representation of an arbitrary value.
1315// Topics: Function Literals, String Operators
1316// See Also: f_len(), f_chr(), f_ord(), f_str(), f_str2(), f_str3()
1317// Usage:
1318//   fn = f_str();
1319//   fn = f_str(a);
1320// Description:
1321//   A factory that generates function literals based on `str(a)`, where the `a`
1322//   argument can optionally be replaced with a constant.
1323// Arguments:
1324//   a = If given, replaces the argument.
1325function f_str(a) = f_1arg(function(a) str(a))(a);
1326
1327
1328// Function: f_str2()
1329// Synopsis: Returns a function to concatenate the string representations of two arbitrary values.
1330// Topics: Function Literals, String Operators
1331// See Also: f_len(), f_chr(), f_ord(), f_str(), f_str2(), f_str3()
1332// Usage:
1333//   fn = f_str2();
1334//   fn = f_str2(a=);
1335//   fn = f_str2(b);
1336//   fn = f_str2(a=,b=);
1337// Description:
1338//   A factory that generates function literals based on `str(a,b)`, where either
1339//   or both of the `a` or `b` arguments can be replaced with constants.
1340// Arguments:
1341//   a = If given, replaces the first argument.
1342//   b = If given, replaces the second argument.
1343function f_str2(a,b) = f_2arg(function(a,b) str(a,b))(a,b);
1344
1345
1346// Function: f_str3()
1347// Synopsis: Returns a function to concatenate the string representations of three arbitrary values.
1348// Topics: Function Literals, Math Operators
1349// See Also: f_len(), f_chr(), f_ord(), f_str(), f_str2(), f_str3()
1350// Usage:
1351//   fn = f_str3();
1352//   fn = f_str3(a=);
1353//   fn = f_str3(b=);
1354//   fn = f_str3(c=);
1355//   fn = f_str3(a=,b=);
1356//   fn = f_str3(b=,c=);
1357//   fn = f_str3(a=,c=);
1358//   fn = f_str3(a=,b=,c=);
1359// Description:
1360//   A factory that generates function literals based on `str(a,b,c)`, where any
1361//   or all of the `a`, `b`, or`c` arguments can be replaced with constants.
1362// Arguments:
1363//   a = If given, replaces the first argument.
1364//   b = If given, replaces the second argument.
1365//   c = If given, replaces the third argument.
1366function f_str3(a,b,c) = f_3arg(function(a,b,c) str(a,b,c))(a,b,c);
1367
1368
1369
1370//////////////////////////////////////////////////////////////////////
1371// Section: Miscellaneous Operators
1372
1373
1374// Function: f_floor()
1375// Synopsis: Returns a function to calculate the integer floor of a given number.
1376// Topics: Function Literals, Math Operators
1377// See Also: f_floor(), f_ceil(), f_round()
1378// Usage:
1379//   fn = f_floor();
1380//   fn = f_floor(a);
1381// Description:
1382//   A factory that generates function literals based on `floor(a)`, where the `a`
1383//   argument can optionally be replaced with a constant.
1384// Arguments:
1385//   a = If given, replaces the argument.
1386function f_floor(a) = f_1arg(function(a) floor(a))(a);
1387
1388
1389// Function: f_round()
1390// Synopsis: Returns a function to calculate the integer rounding of a given number.
1391// Topics: Function Literals, Math Operators
1392// See Also: f_floor(), f_ceil(), f_round()
1393// Usage:
1394//   fn = f_round();
1395//   fn = f_round(a);
1396// Description:
1397//   A factory that generates function literals based on `round(a)`, where the `a`
1398//   argument can optionally be replaced with a constant.
1399// Arguments:
1400//   a = If given, replaces the argument.
1401function f_round(a) = f_1arg(function(a) round(a))(a);
1402
1403
1404// Function: f_ceil()
1405// Synopsis: Returns a function to calculate the integer ceiling of a given number.
1406// Topics: Function Literals, Math Operators
1407// See Also: f_floor(), f_ceil(), f_round()
1408// Usage:
1409//   fn = f_ceil();
1410//   fn = f_ceil(a);
1411// Description:
1412//   A factory that generates function literals based on `ceil(a)`, where the `a`
1413//   argument can optionally be replaced with a constant.
1414// Arguments:
1415//   a = If given, replaces the argument.
1416function f_ceil(a)  = f_1arg(function(a) ceil(a))(a);
1417
1418
1419// Function: f_abs()
1420// Synopsis: Returns a function to calculate the absolute value of a given number.
1421// Topics: Function Literals, Math Operators
1422// See Also: f_abs(), f_sign(), f_ln(), f_log(), f_exp(), f_sqr(), f_sqrt()
1423// Usage:
1424//   fn = f_abs();
1425//   fn = f_abs(a);
1426// Description:
1427//   A factory that generates function literals based on `abs(a)`, where the `a`
1428//   argument can optionally be replaced with a constant.
1429// Arguments:
1430//   a = If given, replaces the argument.
1431function f_abs(a)   = f_1arg(function(a) abs(a))(a);
1432
1433
1434// Function: f_sign()
1435// Synopsis: Returns a function to calculate the sign of a given number.
1436// Topics: Function Literals, Math Operators
1437// See Also: f_abs(), f_sign(), f_ln(), f_log(), f_exp(), f_sqr(), f_sqrt()
1438// Usage:
1439//   fn = f_sign();
1440//   fn = f_sign(a);
1441// Description:
1442//   A factory that generates function literals based on `sign(a)`, where the `a`
1443//   argument can optionally be replaced with a constant.
1444// Arguments:
1445//   a = If given, replaces the argument.
1446function f_sign(a)  = f_1arg(function(a) sign(a))(a);
1447
1448
1449// Function: f_ln()
1450// Synopsis: Returns a function to calculate the natural logarithm of a given number.
1451// Topics: Function Literals, Math Operators
1452// See Also: f_abs(), f_sign(), f_ln(), f_log(), f_exp(), f_sqr(), f_sqrt()
1453// Usage:
1454//   fn = f_ln();
1455//   fn = f_ln(a);
1456// Description:
1457//   A factory that generates function literals based on `ln(a)`, where the `a`
1458//   argument can optionally be replaced with a constant.
1459// Arguments:
1460//   a = If given, replaces the argument.
1461function f_ln(a)    = f_1arg(function(a) ln(a))(a);
1462
1463
1464// Function: f_log()
1465// Synopsis: Returns a function to calculate the base 10 logarithm of a given number.
1466// Topics: Function Literals, Math Operators
1467// See Also: f_abs(), f_sign(), f_ln(), f_log(), f_exp(), f_sqr(), f_sqrt()
1468// Usage:
1469//   fn = f_log();
1470//   fn = f_log(a);
1471// Description:
1472//   A factory that generates function literals based on `log(a)`, where the `a`
1473//   argument can optionally be replaced with a constant.
1474// Arguments:
1475//   a = If given, replaces the argument.
1476function f_log(a)   = f_1arg(function(a) log(a))(a);
1477
1478
1479// Function: f_exp()
1480// Synopsis: Returns a function to calculate the natural exponent of a given number.
1481// Topics: Function Literals, Math Operators
1482// See Also: f_abs(), f_sign(), f_ln(), f_log(), f_exp(), f_sqr(), f_sqrt()
1483// Usage:
1484//   fn = f_exp();
1485//   fn = f_exp(a);
1486// Description:
1487//   A factory that generates function literals based on `exp(a)`, where the `a`
1488//   argument can optionally be replaced with a constant.
1489// Arguments:
1490//   a = If given, replaces the argument.
1491function f_exp(a)   = f_1arg(function(a) exp(a))(a);
1492
1493
1494// Function: f_sqr()
1495// Synopsis: Returns a function to calculate the square of a given number.
1496// Topics: Function Literals, Math Operators
1497// See Also: f_abs(), f_sign(), f_ln(), f_log(), f_exp(), f_sqr(), f_sqrt()
1498// Usage:
1499//   fn = f_sqr();
1500//   fn = f_sqr(a);
1501// Description:
1502//   A factory that generates function literals based on `a*a`, where the `a`
1503//   argument can optionally be replaced with a constant.
1504// Arguments:
1505//   a = If given, replaces the argument.
1506function f_sqr(a)   = f_1arg(function(a) a*a)(a);
1507
1508
1509// Function: f_sqrt()
1510// Synopsis: Returns a function to calculate the square root of a given number.
1511// Topics: Function Literals, Math Operators
1512// See Also: f_abs(), f_sign(), f_ln(), f_log(), f_exp(), f_sqr(), f_sqrt()
1513// Usage:
1514//   fn = f_sqrt();
1515//   fn = f_sqrt(a);
1516// Description:
1517//   A factory that generates function literals based on `sqrt(a)`, where the `a`
1518//   argument can optionally be replaced with a constant.
1519// Arguments:
1520//   a = If given, replaces the argument.
1521function f_sqrt(a)  = f_1arg(function(a) sqrt(a))(a);
1522
1523
1524// Function: f_norm()
1525// Synopsis: Returns a function to calculate the norm of a given vector.
1526// Topics: Function Literals, Vectors
1527// See Also: f_norm(), f_abs(), f_sign(), f_cross()
1528// Usage:
1529//   fn = f_norm();
1530//   fn = f_norm(a);
1531// Description:
1532//   A factory that generates function literals based on `norm(a)`, where the `a`
1533//   argument can optionally be replaced with a constant.
1534// Arguments:
1535//   a = If given, replaces the argument.
1536function f_norm(a)  = f_1arg(function(a) norm(a))(a);
1537
1538
1539// Function: f_cross()
1540// Synopsis: Returns a function to calculate the norm of a given vector.
1541// Topics: Function Literals, Vectors
1542// See Also: f_norm(), f_abs(), f_sign(), f_cross()
1543// Usage:
1544//   fn = f_cross();
1545//   fn = f_cross(a=);
1546//   fn = f_cross(b);
1547//   fn = f_cross(a=,b=);
1548// Description:
1549//   A factory that generates function literals based on `str(a,b)`, where either
1550//   or both of the `a` or `b` arguments can be replaced with constants.
1551// Arguments:
1552//   a = If given, replaces the first argument.
1553//   b = If given, replaces the second argument.
1554function f_cross(a,b) = f_2arg(function(a,b) cross(a,b))(a,b);
1555
1556
1557// Section: Type Queries
1558
1559// Function: f_is_def()
1560// Synopsis: Returns a function to determine if a value is not `undef`.
1561// Topics: Function Literals, Type Queries
1562// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_string(), f_is_list()
1563// Usage:
1564//   fn = f_is_def();
1565// Description:
1566//   A factory that returns function literals equivalent to `is_def(a)`.
1567// Arguments:
1568//   a = If given, replaces the argument.
1569function f_is_def(a) = f_1arg(function (a) is_def(a))(a);
1570
1571
1572// Function: f_is_undef()
1573// Synopsis: Returns a function to determine if a value is `undef`.
1574// Topics: Function Literals, Type Queries
1575// See Also: f_is_bool(), f_is_num(), f_is_string(), f_is_list()
1576// Usage:
1577//   fn = f_is_undef();
1578// Description:
1579//   A factory that returns function literals equivalent to `is_undef(a)`.
1580// Arguments:
1581//   a = If given, replaces the argument.
1582function f_is_undef(a) = f_1arg(function (a) is_undef(a))(a);
1583
1584
1585// Function: f_is_bool()
1586// Synopsis: Returns a function to determine if a value is a boolean.
1587// Topics: Function Literals, Type Queries
1588// See Also: f_is_undef(), f_is_num(), f_is_string(), f_is_list()
1589// Usage:
1590//   fn = f_is_bool();
1591// Description:
1592//   A factory that returns function literals equivalent to `is_bool(a)`.
1593// Arguments:
1594//   a = If given, replaces the argument.
1595function f_is_bool(a) = f_1arg(function (a) is_bool(a))(a);
1596
1597
1598// Function: f_is_num()
1599// Synopsis: Returns a function to determine if a value is a number.
1600// Topics: Function Literals, Type Queries
1601// See Also: f_is_undef(), f_is_bool(), f_is_string(), f_is_list()
1602// Usage:
1603//   fn = f_is_num();
1604// Description:
1605//   A factory that returns function literals equivalent to `is_num(a)`.
1606// Arguments:
1607//   a = If given, replaces the argument.
1608function f_is_num(a) = f_1arg(function (a) is_num(a))(a);
1609
1610
1611// Function: f_is_int()
1612// Synopsis: Returns a function to determine if a value is an integer number.
1613// Topics: Function Literals, Type Queries
1614// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_string(), f_is_list()
1615// Usage:
1616//   fn = f_is_int();
1617// Description:
1618//   A factory that returns function literals equivalent to `is_int(a)`.
1619// Arguments:
1620//   a = If given, replaces the argument.
1621function f_is_int(a) = f_1arg(function (a) is_int(a))(a);
1622
1623
1624// Function: f_is_nan()
1625// Synopsis: Returns a function to determine if a value is a number type that is Not a Number (NaN).
1626// Topics: Function Literals, Type Queries
1627// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1628// Usage:
1629//   fn = f_is_nan();
1630// Description:
1631//   A factory that returns function literals equivalent to `is_nan(a)`.
1632// Arguments:
1633//   a = If given, replaces the argument.
1634function f_is_nan(a) = f_1arg(function (a) is_nan(a))(a);
1635
1636
1637// Function: f_is_finite()
1638// Synopsis: Returns a function to determine if a value is a number type that is finite.
1639// Topics: Function Literals, Type Queries
1640// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1641// Usage:
1642//   fn = f_is_finite();
1643// Description:
1644//   A factory that returns function literals equivalent to `is_finite(a)`.
1645// Arguments:
1646//   a = If given, replaces the argument.
1647function f_is_finite(a) = f_1arg(function (a) is_finite(a))(a);
1648
1649
1650// Function: f_is_string()
1651// Synopsis: Returns a function to determine if a value is a string.
1652// Topics: Function Literals, Type Queries
1653// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_list()
1654// Usage:
1655//   fn = f_is_string();
1656// Description:
1657//   A factory that returns function literals equivalent to `is_string(a)`.
1658// Arguments:
1659//   a = If given, replaces the argument.
1660function f_is_string(a) = f_1arg(function (a) is_string(a))(a);
1661
1662
1663// Function: f_is_list()
1664// Synopsis: Returns a function to determine if a value is a list.
1665// Topics: Function Literals, Type Queries
1666// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1667// Usage:
1668//   fn = f_is_list();
1669// Description:
1670//   A factory that returns function literals equivalent to `is_list(a)`.
1671// Arguments:
1672//   a = If given, replaces the argument.
1673function f_is_list(a) = f_1arg(function (a) is_list(a))(a);
1674
1675
1676// Function: f_is_range()
1677// Synopsis: Returns a function to determine if a value is a range.
1678// Topics: Function Literals, Type Queries
1679// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1680// Usage:
1681//   fn = f_is_range();
1682// Description:
1683//   A factory that returns function literals equivalent to `is_range(a)`.
1684// Arguments:
1685//   a = If given, replaces the argument.
1686function f_is_range(a) = f_1arg(function (a) is_range(a))(a);
1687
1688
1689// Function: f_is_function()
1690// Synopsis: Returns a function to determine if a value is a function literal.
1691// Topics: Function Literals, Type Queries
1692// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1693// Usage:
1694//   fn = f_is_function();
1695// Description:
1696//   A factory that returns function literals equivalent to `is_function(a)`.
1697// Arguments:
1698//   a = If given, replaces the argument.
1699function f_is_function(a) = f_1arg(function (a) is_function(a))(a);
1700
1701
1702// Function: f_is_vector()
1703// Synopsis: Returns a function to determine if a value is a list of numbers.
1704// Topics: Function Literals, Type Queries
1705// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1706// Usage:
1707//   fn = f_is_vector();
1708// Description:
1709//   A factory that returns function literals equivalent to `is_vector(a)`.
1710// Arguments:
1711//   a = If given, replaces the argument.
1712function f_is_vector(a,b) = f_2arg(function (a,b) is_vector(a,b))(a,b);
1713
1714
1715// Function: f_is_path()
1716// Synopsis: Returns a function to determine if a value is a Path (a list of points).
1717// Topics: Function Literals, Type Queries
1718// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1719// Usage:
1720//   fn = f_is_path();
1721// Description:
1722//   A factory that returns function literals equivalent to `is_path(a)`.
1723// Arguments:
1724//   a = If given, replaces the argument.
1725function f_is_path(a,b) = f_2arg(function (a,b) is_path(a,b))(a,b);
1726
1727
1728// Function: f_is_region()
1729// Synopsis: Returns a function to determine if a value is a Region (a list of Paths).
1730// Topics: Function Literals, Type Queries
1731// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1732// Usage:
1733//   fn = f_is_region();
1734// Description:
1735//   A factory that returns function literals equivalent to `is_region(a)`.
1736// Arguments:
1737//   a = If given, replaces the argument.
1738function f_is_region(a) = f_1arg(function (a) is_region(a))(a);
1739
1740
1741// Function: f_is_vnf()
1742// Synopsis: Returns a function to determine if a value is a VNF structure.
1743// Topics: Function Literals, Type Queries
1744// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1745// Usage:
1746//   fn = f_is_vnf();
1747// Description:
1748//   A factory that returns function literals equivalent to `is_vnf(a)`.
1749// Arguments:
1750//   a = If given, replaces the argument.
1751function f_is_vnf(a) = f_1arg(function (a) is_vnf(a))(a);
1752
1753
1754// Function: f_is_patch()
1755// Synopsis: Returns a function to determine if a value is a Bezier Patch structure.
1756// Topics: Function Literals, Type Queries
1757// See Also: f_is_undef(), f_is_bool(), f_is_num(), f_is_int(), f_is_string(), f_is_list()
1758// Usage:
1759//   fn = f_is_patch();
1760// Description:
1761//   A factory that returns function literals equivalent to `is_patch(a)`.
1762// Arguments:
1763//   a = If given, replaces the argument.
1764function f_is_patch(a) = f_1arg(function (a) is_patch(a))(a);
1765
1766
1767
1768// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap