Hello,
Here's a 'compose' macro.
(define-syntax compose
(syntax-rules ()
( (compose (f g) (x ...))
(lambda (x ...)
(f (g x ...))) )
( (compose (f g ...) (x ...))
(lambda (x ...)
(f ((compose (g ...) (x ...)) x ...))) )
( (compose (f ...))
(compose (f ...) (x)) )))
Simple cases:
((compose (sqrt sqrt)) 16)
((compose (sqrt sqrt sqrt)) 256)
What if the procedure should accept more than one value?
((compose (sqrt +) (x y)) 1 15)
I.e. the second parameter is used to indicate the resulting procedure's
arity.
The Factor programming language supports a concept called "smart
combinators". Basically, you can write a macro which expands according
to the arity of the input functions.
So for example, a "smart" compose wouldn't need the '(x y)' here:
((compose (sqrt +) (x y)) 1 15)
It would notice that '+' has n-arity and expand accordingly.
So my question is, has this topic come up in the Scheme language design
world?
Syntax-case is powerful enough for this style of macro; it's just
limited by not being able to get arity information in this case.
Ed