This is a collection of functions I've found useful for
functional programming tasks. The most useful is PARTIALX
(short-name PLX) which partially applies a function to any
number of arguments at any point of it's argument list.
Example:
(map
(plx + 10 #f)
(list 0 1 2 3 4)) -> (10 11 12 13 14)
I've found this method of constructing functions on the
fly, so to speak, very useful and so I've decided to share
it with the community after using it myself for a few months.
Good for the "visitor pattern". Please let me know about
any bugs, weirdnesses or generally unschemely things. I am
still somewhat new to the language.
(partiall fun val)
partially applies fun to val, val fixing the
left-most argument to fun
(partialr fun val)
partially applies fun to val, val fixing the right most argument to fun
(make-arg-list null-symbol curried-args partial-list)
constructs the argument list to be passed to a function which has
been partially evaluated.
PARTIAL-LIST is the list of arguments passed to the PARTIALX
procedure where some elements are equal to NULL-SYMBOL,
indicating that they should be replaced by CURRIED-ARGS in the
same order.
NULL-SYMBOL is either a symbol or false indicating which
arguments in PARTIAL-LIST are provided by the partially applied
function.
CURRIED-ARGS are the
arguments to put in the slots of PARTIAL-LIST see also: PARTIALX
(partialx fun arg-or#f ...)
partially applies fun to the
arguments, leaving "unfixed" arguments which are false.
(partialx sym fun arg-or-sym ...) partially applies fun to the
arguments leaving "unfixed" all the values equal to sim.
Example:
(map
(partialx + 10 #f)
(list 0 1 2 3 4)) -> (10 11 12 13 14)
(map
(partialx 'tail string-append "dogs" 'tail)
(list "are awesome" "are not awesome"))
-> ("dogs are awesome" "dogs are not awesome")
For convenience, a nickname is provided via PLX,
which is just this function.
(fix f arg0)
Repeatedly applies f to arg (and subsequent results)
until two successive results are equal by "eq?".
(fix f arg0 predicate)
like above but uses PREDICATE for equality.
(map-apply f list)
equivalent to (map (plx apply f #f) list)