Lisp-like macros for C?

J

jsykari

Has anyone ever implemented lisp-like macros for C?

Or any similar pursuits?

(I'm aware of MetaC, but that's not quite it.)

Antti
 
L

ld

Has anyone ever implemented lisp-like macros for C?

Or any similar pursuits?

(I'm aware of MetaC, but that's not quite it.)

Maybe the cpp library chaos-pp could be of interest for you?

cheers,

ld.
 
N

Nick Keighley

Has anyone ever implemented lisp-like macros for C?

Or any similar pursuits?

(I'm aware of MetaC, but that's not quite it.)

what on earth would they look like? Isn't the point of lisp-like
macros based on the programs-look-like-data idea?
 
E

Eric Sosman

jsykari said:
Has anyone ever implemented lisp-like macros for C?

I was working on some, but my parenthesis key broke
from overuse.
Or any similar pursuits?

(I'm aware of MetaC, but that's not quite it.)

Perhaps if you'd describe what you mean by "it" and
by "lisp-like," people would be able to help. As it is,
I've no idea what you're looking for, or why.
 
K

Kenny McCormack

I was working on some, but my parenthesis key broke
from overuse.


Perhaps if you'd describe what you mean by "it" and
by "lisp-like," people would be able to help. As it is,
I've no idea what you're looking for, or why.

I think this is one of those things where if you have to have it
explained to you, you won't be of any help. I.e./OTOH, if you understand
what the OP is talking about, then you are likely to be able to help him
(and if not, you should just be quiet and move on).

(Like you, I have no idea what he is talking about either)

P.S. To the OP: And if you do explain it here (which you shouldn't have
to [see above]), all you'll get for your trouble is abuse.
 
P

Phil Carmody

Nick Keighley said:
what on earth would they look like? Isn't the point of lisp-like
macros based on the programs-look-like-data idea?

I believe some were bandied around this newsgroup in about 1993-ish.
They wouldn't fool a real lisp user, but let one create reasonably
lisp-like chunks of code. As a one-time scheme hacker, they at least
raised a chortle here for being a good attempt. I couldn't recreate
them if I tried, alas, which is a shame.

Phil
 
J

jsykari

     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
 
J

jsykari

I believe some were bandied around this newsgroup in about 1993-ish.
They wouldn't fool a real lisp user, but let one create reasonably
lisp-like chunks of code. As a one-time scheme hacker, they at least
raised a chortle here for being a good attempt. I couldn't recreate
them if I tried, alas, which is a shame.

I found a paper 1993 from Weise et al., "Programmable Syntax Macros"
Perhaps this is the same thing you remember:

http://www.cs.rice.edu/~taha/teaching/05S/511/papers/weise93programmable.pdf

Anyway, this was pretty much what I was looking for.

Antti
 
D

David Thompson

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.
I've never seen this done in C (which isn't proof of nonexistence).

(IME) the prevailing/popular practice in C when you want more than the
standard preprocessor gives is *separate* tools that generate C source
-- either general-purpose like awk and perl (both somewhat C-like but
not totally) or special-purpose like IDL (RPC) compilers, embedded-SQL
mappers, autoconf, etc. C-pp does have #line and #file directives to
help such separate tools be more transparent.

perl does have eval; (standard/common) awk doesn't, but it can invoke
itself as a child process which gives the same power more clumsily.
None of the tools I know has parsing that would handle full C as
input; they do sometimes use C *style* for more limited input.

These kinds of techniques handle a LOT of useful cases. But if you
need (or want) complete generality -- any bounded manipulation of any
representable program -- I can't help you.

FWIW, PL/I (I believe standardly) has a preprocessor with syntax
slightly tweaked (mostly adding some percent signs) and (quite!)
subset semantics (but still useful). And, inevitably, suffered from
the unresolvable debates between 'heavy preprocessing can much better
express the problem domain' and 'heavy preprocessing makes it too
difficult to understand what the actual code is'.
 
W

wolfgang.riedel

FWIW, PL/I (I believe standardly) has a preprocessor with syntax
slightly tweaked (mostly adding some percent signs) and (quite!)
subset semantics (but still useful). And, inevitably, suffered from
the unresolvable debates between 'heavy preprocessing can much better
express the problem domain' and 'heavy preprocessing makes it too
difficult to understand what the actual code is'.

True, AFAIK, the PL/1 PP is Turing complete, but you need PL/1 itself.
For an arcane, but free and widely deployed PP. look up M4 used in
autotools
and sendmail.

Greetings,
Wolfgang

PS.: or write your own - it's not that difficult, we did this to
handle different DBMS
(those are tricky, as some intercept before the C PP, and so don't
know macro expansions)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top