ยทยทยท@zedat.fu-berlin.de (Stefan Ram) writes:
> For functions of one argument f, g, h, ... an application
> might be written in Cambridge notation as follows
>
> ( f ( g ( h x )))
>
> When this pattern occurs often and possibly to a greater
> depth, one might wish to write it without that many
> parentheses. In mathematics, there is a binary operator "o"
> to combine two functions, so that one might write
>
> ( f o g o h )( x )
>
> Now the number of parentheses needed does not grow with the
> number of functions combined.
>
> Are there means in Lisp with the same effect, possibly
> something like the following?
>
> ( combine f g h x )
>
> (I assume "combine" might be written as a macro, and just
> wonder whether something like this already exist pre-defined
> and if anyone else uses/needs something like this.)
Here is a small macro I've written mostly out of curiosity.
(defmacro push-through (arg &rest functions)
(if functions
(let ((functions (reverse functions)))
`(,(car functions) (push-through ,arg ,@ (reverse (cdr functions)))))
arg))
;; an example
(push-through 8
(lambda (x) (+ x 88))
(lambda (x) (* x 3))
(lambda (x) (mod x 1999)))
;; another one
#|
(push-through base-income
add-bonus add-dividends
substract-insurance substract-mortgage)
|#
cheers
---
~rv Planned science is forbidden science. Murray S. Rothbard