Next: , Previous: , Up: srfi specialize-procedures   [Index]


2.15.3 Rationale

A particularly elegant way to deal with specialization is known as currying (Schoenfinkel 1924, Curry 1958). The idea of currying is to reduce multi–argument functions to single–argument functions by regarding an n–ary function as a unary function mapping its first argument into an (n-1)–ary function (which is curried in turn). This point of view, apart from its theoretical elegance, allows an extremely compact notation for specializing the first argument of a function. In the first example, one could simply write (cons 1).

Yet, Scheme is not a curried language—the number of arguments passed to a procedure must match the number of its parameters at all times. This allows zero–arity and variable–arity procedures but in order to specialize parameters one usually has to write down a lambda–expression and invent some irrelevant identifiers for its formal variables (x in the examples in the Abstract). For this reason, the mechanism proposed in this SRFI provides a simple and compact notation for specializing any subset of the parameters of a procedure.

Note: The mechanism proposed here is not currying!

The purpose of the mechanism proposed here is to make the benefits of currying available within the programming language Scheme. There are two primary benefits of currying in practice: Higher–order types are substantially simplified and there is a simple notation for specializing parameters. The type aspect is irrelevant as Scheme has latent typing. The specialization aspect is largly covered with this SRFI.

Here are a few more examples for illustration:

(map (cut * 2 <>) '(1 2 3 4))
(map (cut vector-set! x <> 0) indices)
(for-each (cut write <> port) exprs)
(map (cut <> x y z) (list min max))
(for-each (cut <>) thunks)

Next: , Previous: , Up: srfi specialize-procedures   [Index]