point-free icon indicating copy to clipboard operation
point-free copied to clipboard

Add partial and partialr

Open AlexKnauth opened this issue 8 years ago • 1 comments

partial and partialr are sort of like curry and curryr, but much simpler. They only go "one level down." Unlike curry, the behavior doesn't change when you reduce or widen the procedure's arity (unless the arity causes an error), and partial and partialr fully support keyword arguments.

AlexKnauth avatar Mar 01 '18 18:03 AlexKnauth

I think this belongs in the arguments package, which has a stronger focus on manipulating keyword arguments. Using that package could make the implementation simpler too:

;; arity fixups omitted for brevity
(define/arguments (partial f+args)
  (define f (first (arguments-positional f+args)))
  (define args
    (make-arguments (rest (arguments-positional f+args))
                    (arguments-keyword f+args)))
  (partial/arguments f args))

(define (partial/arguments f partial-args)
  (lambda/arguments args (apply/arguments f (arguments-merge partial-args args))))

This implementation allows overwriting keywords which may or may not be a good idea. For example, ((partial draw #:color 'red) pic #:color 'blue) is equivalent to (draw pic #:color 'blue). Should that raise an arity exception instead?

jackfirth avatar Apr 23 '18 02:04 jackfirth