The more correct (and modern; I don't think SpawnOn was in the released XMonad back then, an awful lot of good stuff was only in darcs) way to do this is to
import XMonad.Actions.SpawnOn
and then use the action
spawnOn "2:code" "emacs"
See http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Actions-SpawnOn.html for details.