Next: , Previous: , Up: Defining a Process   [Contents][Index]

4.2 Process templates

When defining many similar processes, it can be useful to parameterize a single process template. This can be accomplished by defining a procedure that takes any number of arguments and returns a parameterized process. Here’s how to do this somewhat verbosely in plain Scheme:

(define (build-me-a-process thing)
  "Return a process that displays THING."
    (name (string-append "show-" thing))
    (procedure `(display ,thing))))

;; Now use this procedure to build concrete processes.
(define show-fruit
  (build-me-a-process "fruit"))
(define show-kitchen
  (build-me-a-process "kitchen"))
(define show-table
  (build-me-a-process "table"))

As this is a somewhat common thing to do in real workflows, the GWL provides simplified syntax to express the same concepts with a little less effort:

process build-me-a-process (with thing)
    string-append "show-" thing
    ` display ,thing

define show-fruit
  build-me-a-process "fruit"
define show-kitchen
  build-me-a-process "kitchen"
define show-table
  build-me-a-process "table"

The result is the same: you get a procedure build-me-a-process that you can use to define a number of similar processes. In the end you have the three processes show-fruit, show-kitchen, and show-table.