Hello,

Let's simulate 'procedure-arity' functionality for a few procedures:

(define (procedure-arity f)
  (cdr (assq f (list (cons vector-ref  2)
                     (cons vector-set! 3)
                     (cons eq?         2)))))

Here's a basic curry macro:

(define-syntax curry
  (syntax-rules ()
    ((curry (f x)) f)
    ((curry (f x y ...))
     (lambda (x)
       (curry ((lambda (y ...)
                 (f x y ...))
               y ...))) )))

You have to specify the arity of the thing you're currying. For example:

    (curry (vector-set! x y z))

will give you a curried 'vector-set!'.

Below is some pseudo-code for a "smart-curry" which uses procedure-arity. Is something like it possible?

(define-syntax smart-curry
  (lambda (stx)
    (syntax-case stx ()
      ((smart-curry f)

       (with-syntax (((x ...) (generate-temporaries
                               (iota
                                (procedure-arity f)))))
         (syntax (curry (f x ...))))))))

I guess it comes down to, can a macro "eval" that 'f' so that it's a procedure which can then be passed to 'procedure-arity'?

Or is there another approach to something like this?

If stuff like this *is* possible, then I think it's makes a case for 'procedure-arity'.

Ed

Reply via email to