This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see CombinatorsCowan in WG2's repo for R7RS-large.

Combinators­Cowan

cowan
2014-12-22 10:42:54
13history
source

This proposal contains various procedures that return procedures, as well as a few others, drawn from an earlier version of Chicken. Common Lisp has a few of them too, and more come from the Standard Prelude from ''Programming Praxis''.

Combinators

These procedures are documented in an unusual style. Rather than showing only how the procedures themselves are invoked, it also shows how the returned procedures would be invoked. This is done in order to make the descriptions easier to understand. For example, if complement were documented in the standard style, the description would say "Returns a procedure which, when applied to an argument, returns #t when proc would return #f when applied to the same argument, and #f otherwise", which is more convoluted.

((constantly obj ...) arg ...)

Returns the objs as its values, ignoring args.

((complement proc) obj)

Returns #t when (''proc obj'') returns #f, and #f` otherwise.

((compose proc ... ) arg ...)

Passes the args to the first proc, which returns any number of values. These are then passed to the next proc, and so on until the final proc is reached. If there are no procs, returns its arguments as values.

((simple-compose proc ...) arg)

Passes arg to the first proc, which returns one value. This is then passed to the next proc, and so on until the final proc is reached. If there are no procs, returns its argument.

((swap proc) obj1 obj2)

Invokes (''proc obj,,2,, obj,,1,,'')`.

((fst proc) obj1 obj2)

Returns obj1.

((snd proc) obj1 obj2)

Returns obj2.

((conjoin predicate ...) arg ...)

Returns #t if the args satisfy all the predicates, and #f otherwise.

((disjoin predicate ...) arg ...)

Returns #t if the args satisfy any of the predicates.

((each proc ... ) arg ...)

Applies each of the procs in turn to args, discarding the results and returning an unspecified value.

((flip proc) arg1 arg2)

Returns (proc arg2 arg1).

((all-of? predicate)

Applies predicate to each element of list in turn, and immediately returns #f if predicate is not satisfied by that element; otherwise returns #t.

((any-of? predicate) list)

Applies predicate to each element of list in turn, and immediately returns #t if predicate is satisfied by that element; otherwise returns #f.

((map-reduce mapper reducer) list)

Returns `(apply ''reducer'' (''mapper list''))`.

((left-section proc arg ...) obj ...)

Applies proc to args concatenated with objs.

((right-section proc arg ...) obj ...)

Applies proc to objs concatenated with args, where args are in reverse order.

Other procedures

(always obj)

Ignores its arguments and always returns #t.

(never obj)

Ignores its arguments and always returns #f.

(identity obj)

Returns obj.