Added 'when' and a small set of tests associated with the function.

Here's a draft of how `when` could be implemented without NSE.