Here's a related idea I wrote a while ago. lambda* gives you a curried
procedure rather than a procedure that takes all its arguments at
once.

(import (rnrs))

(define-syntax lambda*
  (syntax-rules ()
    ((_ (x x* ...) b b* ...)
     (let ((f (lambda (x x* ...) b b* ...)))
       (...
         (define-syntax cases
           (syntax-rules ()
             ((_ (x^ ...) () f^ (c ...))
              (case-lambda c ...
                ((x^ ...) (f^ x^ ...))
                ((x^ ... . w) (apply (f^ x^ ...) w))))
             ((_ (x^ ...) (y1 y2 ...) f^ (c ...))
              (cases (x^ ... y1) (y2 ...) f^
                (((x^ ...) (lambda* (y1 y2 ...) (f^ x^ ... y1 y2 ...)))
                 c ...))))))
       (cases (x) (x* ...) f ())))))

(define (test) ; some examples:
  (define f (lambda* (x y) (lambda (z) (+ x y z))))
  (define g ((lambda* (x y) (lambda* (z) (lambda* (a b) (+ a b x y
z)))) 1 2 3 4))
  (values
    (f 1)
    (f 1 2)
    (f 1 2 3)
    g
    (g 5)
    (map (lambda* (a b c) (+ a b c)) '(1 2 3) '(4 5 6) '(7 8 9))
    (map (lambda* (a) (lambda* (b c) (+ a b c))) '(1 2 3) '(4 5 6) '(7 8 9))
    (map (lambda* (f) (f 1 2 3))
         (list (lambda* (a b c) (+ a b c))
               (lambda* (a) (lambda* (b c) (+ a b c)))
               (lambda* (a b) (lambda* (c) (+ a b c)))))
    (map (lambda* (f) ((f 1) 2 3))
         (list (lambda* (a b c) (+ a b c))
               (lambda* (a) (lambda* (b c) (+ a b c)))
               (lambda* (a b) (lambda* (c) (+ a b c)))))
    (map (lambda* (f) (((f 1) 2) 3))
         (list (lambda* (a b c) (+ a b c))
               (lambda* (a) (lambda* (b c) (+ a b c)))
               (lambda* (a b) (lambda* (c) (+ a b c)))))
    ))


On Wed, May 27, 2009 at 10:41 AM, Abdulaziz Ghuloum <[email protected]> wrote:
>
> On May 27, 2009, at 3:21 AM, Eduardo Cavazos wrote:
>
>> I have a feeling the above can be simpler...
>
> (define-syntax curry
>  (syntax-rules ()
>    [(_ proc x) (lambda (x) (proc x))]
>    [(_ proc x x* ...)
>     (lambda (x)
>       (curry (lambda (x* ...) (proc x x* ...)) x* ...))]))
>
> :-)
>
> Aziz,,,
>

Reply via email to