Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Lisp-like macros for C?

Reply
Thread Tools

Lisp-like macros for C?

 
 
jsykari
Guest
Posts: n/a
 
      09-30-2009
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
 
Reply With Quote
 
 
 
 
ld
Guest
Posts: n/a
 
      09-30-2009
On 30 sep, 13:10, jsykari <jsyk...@gmail.com> wrote:
> 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.
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      09-30-2009
On 30 Sep, 12:10, jsykari <jsyk...@gmail.com> wrote:

> 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?
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      09-30-2009
jsykari wrote:
> 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.

--
Eric Sosman
lid
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      09-30-2009
In article <h9vmel$8io$>,
Eric Sosman <> wrote:
>jsykari wrote:
>> 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.


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.

 
Reply With Quote
 
Phil Carmody
Guest
Posts: n/a
 
      09-30-2009
Nick Keighley <> writes:
> On 30 Sep, 12:10, jsykari <jsyk...@gmail.com> wrote:
>
>> 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?


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
--
Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
 
Reply With Quote
 
jsykari
Guest
Posts: n/a
 
      10-01-2009
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
 
Reply With Quote
 
jsykari
Guest
Posts: n/a
 
      10-01-2009
On Sep 30, 11:53*pm, Phil Carmody <thefatphil_demun...@yahoo.co.uk>
wrote:
> Nick Keighley <nick_keighley_nos...@hotmail.com> writes:
> > On 30 Sep, 12:10, jsykari <jsyk...@gmail.com> wrote:

>
> >> 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?

>
> 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/teachin...ogrammable.pdf

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

Antti
 
Reply With Quote
 
David Thompson
Guest
Posts: n/a
 
      10-12-2009
On Thu, 1 Oct 2009 00:22:09 -0700 (PDT), jsykari <>
wrote:

> 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'.

 
Reply With Quote
 
wolfgang.riedel
Guest
Posts: n/a
 
      10-14-2009

> 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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
macros-loop? calling macros X times? Andrew Arro C Programming 2 07-24-2004 09:52 AM
Explanation of macros; Haskell macros mike420@ziplip.com Python 80 11-07-2003 02:22 AM
Re: Explanation of macros; Haskell macros Michael T. Babcock Python 0 11-03-2003 01:54 PM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 5 11-01-2003 01:09 AM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 1 10-07-2003 04:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57