[racket] question on pluggable modules

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Nov 3 18:49:41 EST 2013

I tend to define such constants in a file dubbed 'basics' and require it everywhere. See 

 https://github.com/mfelleisen/Acquire

for example. There 'basics' contains the constants I need for most of the game implementation and some simple functions too. 

-- Matthias






On Nov 3, 2013, at 12:45 PM, Stephen Bloch wrote:

> 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
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.