https://github.com/takagi/cl-cuda/blob/master/examples/vecto...
I though that Julia had macros, so I don't understand why what you propose is not possible (note to self: find time to learn Julia).