Skip to content

Instantly share code, notes, and snippets.

@tioover
Forked from Javran/gist:8142839
Last active January 1, 2016 12:09
Show Gist options
  • Save tioover/8142955 to your computer and use it in GitHub Desktop.
Save tioover/8142955 to your computer and use it in GitHub Desktop.
#lang racket
(define (curry f)
(define (min-arity arity)
(if (number? arity) arity (arity-at-least-value arity)))
(define (curry-aux f args arity)
(lambda (a)
(let ((new-args (cons a args)))
(cond ((= arity 1)
(apply f (reverse new-args)))
((> arity 1)
(curry-aux f new-args (- arity 1)))
; fail otherwise
))))
(curry-aux f '() (min-arity (procedure-arity f))))
(define (appc . l)
(if (eq? (cdr l) '())
(car l)
(apply appc
(cons ((car l) (cadr l)) (cdr (cdr l))))))
@tioover
Copy link
Author

tioover commented Dec 27, 2013

example

 (appc (curry (lambda (a b) (+ a b))) 1 2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment