cmacro icon indicating copy to clipboard operation
cmacro copied to clipboard

Macros that write macros

Open porky11 opened this issue 7 years ago • 3 comments

I'd like to create some templates similar to c++

template mover <T N> {
  T[N] pos;
  T[N] vel;
}

I don't know how I would write a macro for this, that replaces T and N in the body. But the I'd need to create a macro that writes a macro like the first one in following example

macro mover {
  case {
    match {
      < $(type) $(length) >
    }
    template {
      {
        $(type) [$(length)] pos;
        $(type) [$(length)] vel;
      }
    }
  }
}

struct mover <int 2> x;

This will cmc to following c-code

struct {
  int [2] pos;
  int [2] vel;
} x;

Another problem is, that macros written by macros don't get expanded by cmc, I have to run cmc multiple times.

porky11 avatar Jul 19 '16 22:07 porky11

I think what's missing is an 'escape' operator. It would be nice to have.

ib00 avatar Aug 02 '22 13:08 ib00

This is an 8-year-old unmaintained project.

eudoxia0 avatar Aug 03 '22 22:08 eudoxia0

I haven’t done anything on this project but apparently subscribed to these messages. So please take this as a humble opinion and i wish one day i would have the motive to work on this project. So my thoughts is, since this is Common Lisp, if something was working last decade, it should work the next decade too ;) Thus even if this project is unmaintained, it’s good to put ideas about improvement. We don’t know maybe someone will want to add the requested feature :)

albuspiroglu avatar Oct 19 '22 23:10 albuspiroglu