(lispkit combinator)
Last updated
Last updated
Library (lispkit combinator)
defines abstractions for combinator-style programming. It provides means to create and compose functions.
(const c ...)
Returns a function accepting any number of arguments and returning the values c
... .
(flip f)
Takes a function with two parameters and returns an equivalent function where the two parameters are swapped.
(negate f)
Returns a function which invokes f
and returns the logical negation.
(partial f arg ...)
Applies arguments arg ... partially to f and returns a new function accepting the remaining arguments. For a function (f a1 a2 a3 ... an)
, (partial f a1 a2)
will return a function (lambda (a3 ... an) (f a1 a2 a3 ... an))
.
(compose f ...)
Composes the given functions f ... such that ((compose f1 f2 ... fn) x)
is equivalent to (f1 (f2 (... (fn x))))
. compose
supports functions returning multiple arguments.
(o f ...)
Composes the given functions f ... such that ((o f1 f2 ... fn) x)
is equivalent to (f1 (f2 (... (fn x))))
. o
is a more efficient version of compose
which only works if the involved functions only return a single argument. compose
is more general and supports functions returning multiple arguments.
(conjoin f ...)
Returns a function invoking all functions f ... and combining the results with and
. ((conjoin f1 f2 ...) x ...)
is equivalent to (and (f1 x ...) (f2 x ...) ...)
.
Returns a function invoking all functions f ... and combining the results with or
. ((disjoin f1 f2 ...) x ...)
is equivalent to (or (f1 x ...) (f2 x ...) ...)
.
Returns a predicate which takes a list as its argument and returns #t
if for every element x of the list (f x) returns true.
Returns a function which applies the functions f
... each individually to its arguments in the given order, returning the result of the last function application.
Special form cut
transforms an expression (f arg ...) into a lambda expression with as many formal variables as there are slots <>
in the expression (f arg ...). The body of the resulting lambda expression calls procedure f with arguments arg ... in the order they appear. In case there is a rest symbol <...>
at the end, the resulting procedure is of variable arity, and the body calls f with all arguments provided to the actual call of the specialized procedure.
Special form cute
is similar to cut
, except that it first binds new variables to the result of evaluating the non-slot expressions (in an unspecific order) and then substituting the variables for the non-slot expressions. In effect, cut
evaluates non-slot expressions at the time the resulting procedure is called, whereas cute
evaluates the non-slot expressions at the time the procedure is constructed.
Y combinator for computing a fixed point of a function f. This is a value that is mapped to itself.
(disjoin f ...)
(list-of? f)
(each f ...)
(cut f) (cut f <...>) (cut f arg ...) (cut f arg ... <...>)
(cute f) (cute f <...>) (cute f arg ...) (cute f arg ... <...>)
(Y f)