[plt-scheme] Parameterizing Modules with variables

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Sun Apr 20 11:31:01 EDT 2003

Others have mentioned parameters.  If you only need
compile-time configurability you can use units to
parameterise your code.  This has the advantage that
you can instantiate units with different
configurations, but the disadvantage of more syntactic
overhead. For example, MoshiMoshi (a wiki) has a
pipeline of operations that can handle interacting
with the datasource.  The datasource is anything that
implements the required signature and could, for
example, be a CVS repository, a database, or just the
filesystem.  Later stages in the pipeline could record
a changelog, handle file permissions and so on.  By
organising this as units we can plug in different
stages of the pipeline when Moshi is configured
(though we don't have many stages implemented yet).

BTW, its more stylish (to my eye) to parameterise code
with the function it should perform than a flag that
has to be checked.  E.g. Emacs has a variable

If non-nil, the DEL key will erase one character
If nil, the DEL key will erase one character

I'd replace this variable with the actual function
that should be called (say, delete-forward or
delete-backward).  That way your code isn't littered
with conds.  You're probably doing this already but I
thought I'd mention it as people who aren't used to
HOFs often program in the style of the Emacs example.


Email: noelwelsh <at> yahoo <dot> com
Jabber: noelw <at> jabber <dot> org

Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo

Posted on the users mailing list.