[plt-scheme] dynamic-require and contracted code?
dynamic-requires do not work with contracted code, that's right. But,
fwiw, they don't work well very many tools (check syntax, compilation
stand-alone executables in mzc ... basically anything that needs to
process the entire program; with dynamic-require it can't find the
whole program).
So, I would suggest you just don't use dynamic-require. Instead write:
(require (prefix version1: "brute-force.ss")
(prefix version2: "finesse.ss"))
(test version1:my-function)
(test version2:my-function)
If you want to avoid the code-duplication above, I recommend a macro,
rather than dynamic-require.
Robby
At Thu, 27 Oct 2005 12:43:00 -0700 (PDT), Danny Yoo wrote:
> Hi everyone,
>
> I'm trying to write a small timer program to test different
> implementations of a function. Each implementation lives in a separate
> module, and I thought I might write something like this to grab at the
> implementation's function:
>
> ;;;;;;
> (define (extract-make-suffix-tree module-filename)
> (dynamic-require module-filename 'make-suffix-tree))
> ;;;;;;
>
>
> Unfortunately, this gives an error:
>
> ;;;;;;
> > (extract-make-suffix-tree "brute-force.ss")
> dynamic-require: name is provided as syntax: make-suffix-tree by module:
> |,/Users/dyoo/work/aztec/scratch/plt/suffixtree/brute-force|
> ;;;;;;
>
>
> where my brute-force.ss looks like:
>
> ;;;;;;
> (module brute-force mzscheme
> (require (lib "contract.ss"))
>
> (provide/contract (make-suffix-tree (-> label? tree?)))
> (define make-suffix-tree ...))
> ;;;;;;
>
>
> I understand that the contract is binding make-suffix-tree as exported
> syntax, so that's what's causing the issue with dynamic-require. I could
> temporarily turn off the contract while I do performance tests, but that
> feels a little unsatisfactory too.
>
> The best solution I can think of so far is to provide two entry points
> into the implementation, one with contracts, and one without. Something
> like:
>
> ;;;;;;
> (module brute-force mzscheme
> (require (lib "contract.ss"))
>
> (provide/contract (make-suffix-tree (-> label? tree?)))
> (provide make-suffix-tree/without-contract)
>
> (define make-suffix-tree/without-contract ...)
> (define make-suffix-tree make-suffix-tree/without-contract))
> ;;;;;;
>
>
> But is there a nicer way? Any suggestions would be greatly appreciated.
> Thanks!
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme