[racket] Macro for code organisation

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Mon Jun 4 18:50:12 EDT 2012

I have a data-structure called pixel-graph representing a collection
of graphs.  The data-structure is a vector of structs, each struct
representing a node in a graph.  There is a main function called
"blobify" that determines which nodes are connected in a single graph
and assigns a graph number to those nodes.  This main function uses
helper functions which are internally defined within the main
function, so that  the name of the data-structure doesn't need to be
passed to each helper function each time it is called.  And after all
these internal defines there is a simple loop through the nodes in the
data-structure.

So the code looks something like this.
-------------------------------------------------
#lang racket
(define (blobify pixel-graph)
  ;Helper functions
 (define (blobify-connected-nodes node-number)
   ...refers to pixel-graph and
    the other helper functions...)

  (define (get-node node-number)
    ..refers to pixel-graph...)

  (define (set-node-blob-number! node)
    ...refers to pixel-graph)

  (define (compare-node-numbers node1 node2)
    ...refers to pixel-graph...)

  ;main loop
 (for  ([current-strip pixel-graph])
     (blobify-connected-nodes current-strip)))
------------------------------------------------------

This works fine, but I was wondering if for readability macros could
be use to set up a kind of "internal require" of the helper functions
so I could have the main loop before the internal definitions of the
helper functions it refers to.

Thanks,
Harry Spier

Posted on the users mailing list.