On this page:
6.1 Basic use of clarify and delegate

6 Examples

6.1 Basic use of clarify and delegate

This example shows an implementation of delegate and clarify that together build a message in terms of one set of dependencies.

(require unlike-assets)
(define dependencies
  '(complexity only maddens
    people ingesting lengthy
    elusive documentation))
(define/contract (build-message clear compiler) advance/c
    (apply string (map (λ (unclear) (send compiler lookup unclear))
(define/contract (resolve-dependency clear compiler) advance/c
  (string-ref clear 0))
(define/contract (main clear compiler) advance/c
  (define clear-names (map (λ (unclear) (send compiler clarify unclear))
  (for ([dependency clear-names])
    (send compiler add! dependency clear))
(define compiler (new (class* unlike-compiler% () (super-new)
                        (define/override (clarify unclear)
                          (symbol->string unclear))
                        (define/override (delegate clear)
                          (if (string=? clear "start")
(send compiler add! "start")
(hash-ref (send compiler compile!) "start")
  1. The compiler is informed of a new asset by an unclear name: 'start.

  2. clarify maps the unclear name to "start".

  3. delegate associates "start" to main.

  4. main runs, adding dependencies as a side-effect. build-message is returned as the designated next step to fulfill "start". It will not be called yet.

  5. All dependencies are circulated through clarify and delegate as well, and each end up fulfilled by resolve-dependency as the first letter of their clear names.

  6. build-message runs, joining the first letter of each dependency in the declared order. The output is "COMPILED"