#lang scribble/doc @require["mz.ss"] @title[#:tag "procedures"]{Procedures} @defproc[(procedure? [v any/c]) boolean]{ Returns @scheme[#t] if @scheme[v] is a procedure, @scheme[#f] otherwise.} @defproc[(apply [proc procedure?] [v any/c] ... [lst list?]) any]{ @guideintro["apply"]{@scheme[apply]} Applies @scheme[proc] using the content of @scheme[(list* v ... lst)] as the (by-position) arguments. The given @scheme[proc] must accept as many arguments as the number of @scheme[v]s plus length of @scheme[lst], and it must not require any keyword arguments; otherwise, the @exnraise[exn:fail:contract]. The given @scheme[proc] is called in tail position with respect to the @scheme[apply] call. @examples[ (apply + '(1 2 3)) (apply + 1 2 '(3)) (apply + '()) ]} @defproc[(compose [proc procedure?] ...) procedure?]{ Returns a procedure that composes the given functions, applying the last @scheme[proc] first and the first @scheme[proc] last. The composed functions can consume and produce any number of values, as long as each function produces as many values as the preceding function consumes. @examples[ ((compose - sqrt) 10) ((compose sqrt -) 10) ((compose list split-path) (bytes->path #"/a" 'unix)) ]} @; ---------------------------------------- @section{Keywords and Arity} @defproc[(keyword-apply [proc procedure?] [kw-lst (listof keyword?)] [kw-val-lst list?] [v any/c] ... [lst list?]) any]{ @guideintro["apply"]{@scheme[keyword-apply]} Like @scheme[apply], but @scheme[kw-lst] and @scheme[kw-val-lst] supply by-keyword arguments in addition to the by-position arguments of the @scheme[v]s and @scheme[lst]. The given @scheme[kw-lst] must be sorted using @scheme[keyword* . any)] [plain-proc procedure? (lambda args (keyword-apply proc null null args))]) procedure?]{ Returns a procedure that accepts all keyword arguments (without requiring any keyword arguments). When the result is called with keyword arguments, then @scheme[proc] is called; the first argument is a list of keywords sorted by @scheme[keyword