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
2012-12-07 13:38:01
6history
source

This proposal contains various procedures that return procedures and a few others, drawn from Chicken. Common Lisp has a few of them too.

Combinators

(constantly obj ...)

Returns a procedure that always returns the obj objects as its values, regardless of the number and value of its arguments.

(complement proc)

Returns a procedure that returns the boolean inverse of proc. That is, it returns a true value when proc returns #f, and #f otherwise.

(compose proc ... )

Returns a procedure that represents the composition of its arguments. Any of the procedures may return multiple values, which are passed as arguments to its successor. With zero arguments, (compose) returns a procedure that is functionally equivalent to values.

(simple-compose proc ...)

A variant of compose that does not handle multiple-valued procedures. With zero arguments, returns a procedure that is functionally equivalent to identity.

(conjoin predicate ...)

Returns a procedure that returns #t if its argument satisfies all the predicates.

(disjoin predicate ...)

Returns a procedure that returns #t if its argument satisfies any of the predicates.

(each proc ... )

Returns a procedure that applies each of the procs in turn to its arguments, discarding the results and returning an unspecified value.

(flip proc)

Returns a two-argument procedure that calls proc, a two-argument procedure, with its arguments swapped.

(all-of? predicate)

Returns a procedure of one argument that returns #t when applied to a list of elements that all satisfy predicate, or #f otherwise.

(any-of? predicate)

Returns a procedure of one argument that returns #t when applied to a list of elements at least one of which satisfies predicate, or #f otherwise.

(map-reduce mapper reducer)

Returns a procedure that applies mapper to each of its arguments, and then applies reducer to all the results and returns what it returns.

Other procedures

(always obj)

Ignores its arguments and always returns #t.

(never obj)

Ignores its arguments and always returns #f.

(identity obj)

Returns obj.

Documentation style

It's been suggested that the documentation of these combinators is too hard to understand, and should be documented like this:

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

Ignores args and returns objs.