Jack Miller with a look at handyLock, the free Bluetooth proximity lock for your Mac.
Install handyLock on your Mac and Pair it up with Bluetooth on your iPhone (also works with Android devices, iPad, et al).
Use the sliders to control the lock distance from Closer to Farther away, and the reaction speed from Faster to Slower.
Otherwise, that’s it. When you and your iPhone get up and move away from the Mac, handyLock senses you’ve moved and locks up the Mac until you return.
Two things come to mind. First, it’s free. Second, why isn’t it a part of iOS and OS X already?