
Magma: Extending C with macros - eudox
https://github.com/eudoxia0/magma
======
breadbox
A cool idea, though the it's in need of some better examples to show its true
power. Several of the examples can be accomplished with the traditional C
preprocessor. For example:

    
    
        #define with_open_file(fp, path, mode)   \
            for (FILE *fp = fopen(path, mode) ; fp ; fclose(fp), fp = 0)

~~~
agumonkey
I don't write C code, isn't this idle code ?

~~~
oso2k
No, it's not an infinite loop. If fp comes back as NULL from the initializer
part of the loop, then the for loop exits.

~~~
baruch
Unless someone used continue inside that loop by mistake...

~~~
xamuel
Using "continue" in that loop is harmless, it causes the file pointer to be
closed and the loop to terminate. Calling "break" is more harmful though, as
it would cause the loop to terminate without closing the file, a memory leak.

------
thechao
Just to completely hijack this whole thought... Bjarne S. has pitched 'smart
references' as a library feature for C++, for the fourth time. Smart
references require adding overload capability for operator..

It seems that by adding operator;, operator if, operator for, etc., we could
use Veldhuizen-style expression-templates to have a two-stage macro-system in
C++.

Obviously, a two-stage macro-system is not as capable as fully general macro
system. However, it seems to me that we get the most bang for the buck from
the first lift, and lifts above the first are not as common. Although, my use
of Lisp-like macros is very limited—perhaps I'm just wrong?

------
sklogic
Nice implementation, I like how the toplevel lifting is done. I was exploring
similar things from a slightly different angle (using PEG natural
extensibility):
[https://github.com/combinatorylogic/clike](https://github.com/combinatorylogic/clike)

------
stefantalpalaru
implemented with a Common Lisp preprocessor:
[https://github.com/eudoxia0/cmacro](https://github.com/eudoxia0/cmacro)

