anonymous curried procedures? also, is your curry better than my case-lambda approach? yours is about the same amount of code, and possibly more efficient... I don't know
On Wed, May 27, 2009 at 5:20 PM, Derick Eddington <[email protected]> wrote: > On Tue, 2009-05-26 at 18:36 -0500, Eduardo Cavazos wrote: >> Hello, >> >> Here's a simple procedure: >> >> (define (subtract-from n) >> (lambda (m) >> (- n m))) >> >> subtract-from is essentially a two parameter '-' which is curried, left >> to right. >> >> I don't recall a traditional/defacto way to express this. Any ideas or >> suggestions? > > I have my (xitomatl curry) library (pasted below) which supports "rest" > arguments and applying any number of arguments at a time: > >> (import (xitomatl curry)) >> (define/curry (f a b c . r) > (apply + a b c r)) >> (f 1 2 3 4) > 10 >> ((f 1 2) 3 4 5 6) > 21 >> (((f 1) 2) 3) > 6 >> > > I just made it when I was bored, so now I'm wondering if I could enhance > it in any ways...? > > -- > : Derick > ---------------------------------------------------------------- > > > (library (xitomatl curry) > (export > define/curry > curry) > (import > (rnrs) > (only (xitomatl define) define/?) > (only (xitomatl predicates) positive-integer?)) > > (define-syntax define/curry > (lambda (stx) > (syntax-case stx () > [(_ (name a ... . r) . body) > (and (identifier? #'name) > (positive? (length #'(a ....)))) > #`(define name > (curry > (lambda (a ... . r) . body) > #,(length #'(a ...))))]))) > > (define/? (curry proc [n positive-integer?]) > (lambda args > (let ([len (length args)]) > (if (>= len n) > (apply proc args) > (curry > (lambda more (apply proc (append args more))) > (- n len)))))) > ) > > >
