Here are some general points before I start on more specific points:
- I don't see any unit tests. Racket programmers often write many unit tests for each function. You can use the
module+
construct andrackunit
to easily write internal unit tests. - Indentation is important for clarity. I couldn't tell that everything was internal to
heap
at first because of the lack of indentation. Also, you can replace some of thelet
s with internaldefine
s and make some of the internal functions into top-level functions to reduce right-ward drift.
More specific points:
- It looks like you're using a dispatch function with internal state to keep track of the priority queue state. The more natural thing to do in Racket would be to create a new datatype using
struct
. This way, your implementation details don't leak through. - You use a
dispatch
function as the entry point to your simulated object. Simulating OO style in this fashion is not a very natural thing to do in Racket. Racket programmers tend to either use (1) the built-in classes & objects or (2) have a functional API with a function for each operation. - You use
begin
to sequence multiple effecting operations inside functions. These are actually unnecessary since Racket functions can have as many expressions in the body as you like.
Hope that helps. Cheers.