[plt-scheme] code organization question

From: Yoav Goldberg (yoav.goldberg at gmail.com)
Date: Sun Oct 16 19:23:27 EDT 2005

I am rather new to PLT's modules and units, and to writing somewhat
large-scale scheme code.
I would like to hear your comments about the best way to handle the
following situation:

(The code is a library for musical objects.)

I have a type "sound", which is a collection of sound-related things.
It can be partially specified (ie have some missing elements), and is
constructed with a keywords like syntax:

(make-sound 'pitch: (make-pitch '(B b) 4) 'duration:
(make-duration-from-wholes 1/4))

sound doesn't know and doesn't really care what it holds, it's just a

Sound is defined in the "sound" module.

"make-pitch" and "make-duration-from-wholes" are provided by modules
which are required by the user of "sound", different users might use
"sound" with different kinds of pitches and durations.

However, writing the complete form:

(make-sound 'pitch: (make-pitch '(B b) 4))

is somewhat tedious, and I would like to have make-sound take a shorter form:

(make-sound 'pitch: '((B b) 4) 'duration: 1/4)

and let it call the appropriate constructors on the values.

Naturally, this requires sound to know the constructors, and those
change between different users of sound.

Now, the question is, what's the best approach to take here?
The options I see are:

1/ some kind of a wrapper macro:
(with-constructors ((pitch: make-pitch) (duration: make-duration-from-wholes))
     ;; sound making code

2/ making the various constructors parameters, and make the user set
them (or use parameterize) after he "require"s sound.

3/ making sound a unit

I think (1) is a rather lousy option, and tend toward one of the other 2.
Which do you think is better? Or do you see any option which is better
Also, if you think I'm "getting it all wrong", and you can think of a
totally different design, please let me know as well.


Posted on the users mailing list.