[racket] question on pluggable modules

From: Stephen Bloch (bloch at adelphi.edu)
Date: Sun Nov 3 12:45:00 EST 2013

Program P uses several functions (say, f and g) which can be implemented in several different ways (think of (f,g) as a Java interface, with (f1,g1) as one implementing class, (f2,g2) as another implementing class, etc.)  I'd like to be able to run the program with one implementation, then with minimal effort run it again with a different implementation.

The f and g functions, naturally, take some information from P.  But some of the information they need really is changeable from one call to the next (make it parameters to f and g), while other information is read from a data file on each invocation of P, and won't change for the duration of that run of P, so it feels more natural to store that information in a global constant C.

If I were putting implementations of f & g in the same source file with P, I would just define C in that source file, and implementations of f & g could refer to it by name.  But putting the implementations of f & g into the main source file makes it a pain to plug in a different implementation.  If C were simple to define, I would provide it from another source file that all these other files require… but C is defined by parsing a data file; is that going to happen once for each source file that requires it?

What's an "approved" way to structure this sort of thing?  Is this a job for parameterize?

(In case you're curious about the application, it's an animated visualization of a graph-coloring problem, and I want to have students plug in their own algorithms for graph-coloring.  C is the adjacency relation, the list of available colors, a couple of things like that.  My students have never heard of parameterize, but that's the least of my worries right now.)


Stephen Bloch
sbloch at adelphi.edu
GPG key at http://home.adelphi.edu/sbloch/sbloch.pubkey.asc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.racket-lang.org/users/archive/attachments/20131103/311a5b15/attachment-0001.sig>

Posted on the users mailing list.