title: Dynamically loading modules in Racket
body: <p>For a project I am creating a class <code>driver%</code> which is supposed to be a layer of abstraction over different modules providing the same procedures. The class would be initialized with an argument that specifies the module to be used.</p>
  <p>Additionally, I would like <code>driver%</code> to expose the same procedures but without side effects, to facilitate unit testing classes that use the driver.</p>
  <p>Consider the following:</p>
  <strong><code>module_one.rkt</code></strong>
  <pre><code>#lang racket
  (provide foo)
  (define (foo)
    (display &quot;called from &quot;module one&quot;))
  </code></pre>
  <strong><code>module_two.rkt</code></strong>
  <pre><code>#lang racket
  (provide foo)
  (define (foo)
    (display &quot;called from &quot;module two&quot;))
  </code></pre>
  <strong><code>driver.rkt</code></strong>
  <pre><code>#lang racket
  (require (prefix-in one: &quot;module_one.rkt&quot;)
           (prefix-in two: &quot;module_two.rkt&quot;))
  
  (provide driver%)
  
  (define driver%
    (class object%
           (super-new)
           (init driver-choice)
           (define choice driver-choice)
           (define/public (foo)
             (case choice
               [(1) (one:foo)]
               [(2) (two:foo)]
               [else void]))))       
  </code></pre>
  <p>This fulfills the above requirements, but is not very elegant: for each exposed procedure, another case expression will have to be added. This seems unnecessary, as the choice for an API is made when the class is instantiated, so the choice will be the same everywhere.</p>
  <p>What would be a more acceptable solution to this problem? I have looked into using <code>local-require</code>, but this does not seem to work with <code>define/public</code>.</p>
  <p>Many thanks!</p>