[plt-scheme] Why do layman programmers care about Currying?

From: Joe Marshall (jmarshall at alum.mit.edu)
Date: Fri Jan 2 17:11:24 EST 2009

2009/1/2 Grant Rettke <grettke at acm.org>:
> I don't understand the practical application of currying in Scheme, so
> I'm not asking about one or the other; the wikipedia link was just my
> going in position on trying to understand what is currying.
> When you do apply the latter, what are the idioms or patterns that you
> most often encounter?

Your best bet would be to look at existing Scheme code.  I found this
example in the MIT Scheme loader:

(define (fasloader->loader loader)
  (lambda (environment purify?)
    (let ((scode (loader)))
      (if purify? (purify (load/purification-root scode)))
      (extended-scode-eval scode environment))))

(define (source-loader pathname)
  (lambda (environment purify?)
    (call-with-input-file pathname
      (lambda (port)
        (let loop ((value unspecific))
          (let ((sexp (read port environment)))
            (if (eof-object? sexp)
                (loop (repl-eval sexp environment)))))))))

(define (wrap-loader pathname loader)
  (lambda (environment purify?)
    (lambda ()
      (with-load-environment environment
        (lambda ()
          (with-eval-unit (pathname->uri pathname)
            (lambda ()
              (loader environment purify?))))))))

Each of these curried functions expect an environment and a boolean.
When you load a file, a procedure called `choose-load-method' is
invoked and it calls one of these procedures.  The caller of
`choose-load-method' can then invoke the appropriate method to
actually get the code loaded.


Posted on the users mailing list.