This is quite similar to the staged functions macro that Jeff posted a long time ago. I used a similar technique in broadcast.jl to generate specialized broadcast functions on demand. I agree with Stefan that you could get rid of the second eval, though.
Use cases for staged functions seem to pop up once ina while, perhaps it's time to revive them?
