4 ms·
> why don't languages provide the ability to do this kind of thing automagically, I mean marking some code to be executed at compile time and act as a code gene
by merijnv 14y ago
> why don't languages provide the ability to do this kind of thing automagically, I mean marking some code to be executed at compile time and act as a code generation feature?
There's certainly already languages that do this type of thing. Haskell has Template Haskell which lets you execute Haskell code at compile time to generate code. I'm pretty sure multiple ML's also have similar meta-programming features.
It works rather nice, actually.
- bad_user 14y agoScala 2.10 will have it too. There is a distinction to be made. In non-homoiconic languages writing macros takes a lot of effort, while in Lisp it's very natural. On the other hand I don't feel that's an advantage for Lisp, because macros are not composable as functions are and you have to really grok Lisp in order to write macros effectively and also recognize instances where they are appropriate.
- Peaker 14y agoI don't think writing Template Haskell macros takes a lot of effort. It is probably harder than Lisp macros, but the main effort is studying the TH API once.