aliquote.org

September 28, 2019

TIL about Racket curry and curryr, a higher-order function which returns a curried version of a given procedure. When the arity is known in advance, e.g. 2, this amounts to (define (curry f) (λ (x) (λ (y) (f x y)))). As an application, think of converting string to their equivalent representation as ASCII values:

(define (string->num s)
  (define base (sub1 (char->integer #\A)))
  (map ((curryr -) base) (map char->integer (string->list s))))