On Sep 30, 4:28*pm, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> jsykari wrote:
> > Has anyone ever implemented lisp-like macros for C?
>
> * * *Perhaps if you'd describe what you mean by "it" and
> by "lisp-like," people would be able to help.
Let me elaborate (the risk of abuse notwithstanding):
Lisp macros (the ones in Common Lisp, not the hygienic variety
provided by Scheme) are
an instance of compile-time metaprogramming, which lets the programmer
do arbitrary
AST-level transformations to the program code before or during
compilation.
The difference between standard C preprocessor and Lisp macros is that
Lisp allows you to
use Lisp itself to perform the transformations, therefore giving much
more power to the
programmer.
I'm looking for a macro language/preprocessor for C that gives me the
power of C to preprocess C programs. In practice, this would mean that
the compiler/preprocessor would have to include a C interpreter and
facilities for generating and analyzing C constructs.
> what on earth would they look like? Isn't the point of lisp-like
> macros based on the programs-look-like-data idea?
Programs-look-like-data certainly helps when implementing them, but is
not a necessity.
Examples of metaprogramming/macro systems that have "real syntax"
include MetaLua (
http://www.haskell.org/th/), Template Haskell (http://
www.haskell.org/th/), Converge (
http://convergepl.org/documentation/
1.1/ctmp/) and Nemerle (
http://nemerle.org).
> Maybe the cpp library chaos-pp could be of interest for you?
Thanks for the pointer. I've taken a look at Chaos and Boost
preprocessor
libraries but they don't quite cut it. While Cpp can be made to
perform
impressive feats, it is still basically a glorified search-and-replace
tool.
Antti