[racket] Scheme Design Patterns

From: Chad A. (chad at neomantic.com)
Date: Mon Sep 9 22:24:32 EDT 2013

Hi,

I'm wondering if someone can help me understand a design-pattern that
I have noticed in the Racket code base. (I'm teaching myself, so
review other people's code alot).

I've seen this pattern..which is a bit contrived.

(define (say-hello)
  (define (display-hello)
     (display "hello")))

So this produces a producer, and to evaluate it I would need to write
((hello)) => "hello"

But then I see this...

(define say-hi (say-hello)).  When I evaluate (say-hello), I get
"hello".  Obviously, the definition of "say-hi" contains the evaluated
(say-hello) than returns the 'display-hello' procedure to be
evaluated.

My question is...why would I want to write the code like this? 3
definitions have been created which could easily be compressed into
one.

 (I also see nothing in the code I'm looking at that appears to
capture a binding via a closure).

Thanks in advance for any insights someone can share.

Chad

Posted on the users mailing list.