Sunday, March 8, 2015

Separating Mars Rover code into different name spaces

I've separated the Mars Rover kata code I started in a previous post into different namespaces.

This is the new directory structure in which there are three new name spaces: commands, worlds and rover. The commands name space contains the code in charge of creating the commands from the messages received:

The rover name space contains the rover factory function and the command multimethods that are applied on rovers:

and the worlds name space contains the code related to wrapping rovers in a world and detecting obstacles: I also simplified the application of commands to the rover in the core name space by using a closure so that the apply-command function captures the world instead of passing it in the reduce accumulator as I was doing before:

I also learned how to use :refer to require only specific symbols from a name space. I'm also using it in the tests (which except for that are exactly as in the previous version of the code).

I think the code has a better structure now.

You can find the code in this GitHub repository.

-----------

Update: I continued working in this code on Mars Rover code version using protocols instead of multimethods and Mars Rover using a finite state machine implemented with mutually recursive functions and trampoline

No comments:

Post a Comment