What if one of the procedures you want to compose returns a number of
values other than 1?

As for not having to provide the number of arguments for the
composition, have you tried writing a version of compose using (lambda
arglist body) and apply rather than (lambda (x ...) body)?

On Thu, Sep 3, 2009 at 10:47 PM, Eduardo Cavazos<[email protected]> wrote:
> 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
>

Reply via email to