Lisp-like macros for C?

Discussion in 'C Programming' started by jsykari, Sep 30, 2009.

  1. jsykari

    jsykari Guest

    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
     
    jsykari, Sep 30, 2009
    #1
    1. Advertising

  2. jsykari

    ld Guest

    On 30 sep, 13:10, jsykari <> 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.
     
    ld, Sep 30, 2009
    #2
    1. Advertising

  3. On 30 Sep, 12:10, jsykari <> 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?
     
    Nick Keighley, Sep 30, 2009
    #3
  4. jsykari

    Eric Sosman Guest

    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
     
    Eric Sosman, Sep 30, 2009
    #4
  5. In article <h9vmel$8io$-september.org>,
    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.
     
    Kenny McCormack, Sep 30, 2009
    #5
  6. jsykari

    Phil Carmody Guest

    Nick Keighley <> writes:
    > On 30 Sep, 12:10, jsykari <> 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
     
    Phil Carmody, Sep 30, 2009
    #6
  7. jsykari

    jsykari Guest

    On Sep 30, 4:28 pm, Eric Sosman <> 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
     
    jsykari, Oct 1, 2009
    #7
  8. jsykari

    jsykari Guest

    On Sep 30, 11:53 pm, Phil Carmody <>
    wrote:
    > Nick Keighley <> writes:
    > > On 30 Sep, 12:10, jsykari <> 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/teaching/05S/511/papers/weise93programmable.pdf

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

    Antti
     
    jsykari, Oct 1, 2009
    #8
  9. 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'.
     
    David Thompson, Oct 12, 2009
    #9

  10. > 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)
     
    wolfgang.riedel, Oct 14, 2009
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    16
    Views:
    489
    Kaz Kylheku
    Oct 28, 2003
  2. Anthony de Almeida Lopes

    Macros within function-like macros?

    Anthony de Almeida Lopes, Dec 26, 2005, in forum: C Programming
    Replies:
    13
    Views:
    781
  3. sturlamolden

    Lisp-like macros in Python?

    sturlamolden, May 1, 2007, in forum: Python
    Replies:
    5
    Views:
    872
    John Nagle
    May 1, 2007
  4. ekzept
    Replies:
    0
    Views:
    390
    ekzept
    Aug 10, 2007
  5. nanothermite911fbibustards
    Replies:
    0
    Views:
    392
    nanothermite911fbibustards
    Jun 16, 2010
Loading...

Share This Page