Eduardo Cavazos wrote:

> I listed 'bi' as:
> 
> (define (bi f g c)
>    (lambda (x)
>      (c (f x)
>         (g x))))
> 
> What about 'cleave' in Scheme? As a macro it's:
> 
> (define-syntax cleave
>   (lambda (stx)
>     (syntax-case stx ()
>       ( (cleave (f ...) c)
>         (with-syntax (((x ...) (generate-temporaries (syntax (f ...)))))
>           (syntax
>            (lambda (x ...)
>              (c (f x)
>                 ...)))) ))))

Yikes! Actually, that's 'spread'! :-)

Here's cleave:

(define-syntax cleave
   (syntax-rules ()
     ( (cleave (f ...) c)
       (lambda (x)
         (c (f x)
            ...)) )))

 > ((cleave (sqrt sin cos) list) 4)
(2 -0.7568024953079282 -0.6536436208636119)
 >

And spread:

(define-syntax spread
   (lambda (stx)
     (syntax-case stx ()
       ((spread (f ...) c)
         (with-syntax (((x ...) (generate-temporaries (syntax (f 
...)))))
           (syntax
            (lambda (x ...)
              (c (f x)
                 ...)))) ))))

 > ((spread (sqrt sin cos) list) 4 0 0)
(2 0 1)
 >

Ed

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to