Re:How to properly use macros in C
by Stratoscope on Sunday December 10, 2017 @04:17PM
(#15893550)
More readable quote:
> One strange phenomenon when coding in C is using macros. This is not something which can be seen in other programming languages (other than C++).
Instead of indenting a quote, use:
> The quote.
or if you want italics to set it off more: > *The quote.*Thanks, TIL.
Macros are fairly common in Rust too.
People who know Lisp are unlikely to be writing blogs about using macros in C.
C and C++ blogs generally tend to be of poor quality, because most of the people writing such things are excited newbies who have fewer years of experience than real experts have abstinence.
Re:How to properly use macros in C
by angry_octet on Tuesday December 12, 2017 @07:52PM
(#15911028)
While your comment provides no evidence in support of its contention, it does support the notion that Lisp programmers have excessive hubris.
Re:How to properly use macros in C
by dangerbird2 on Sunday December 10, 2017 @05:25PM
(#15893821)
Lisp macros directly manipulate the program's abstract syntax tree (in the case of Lisp, it happens to hava a 1-1 relationship to the source code structure). It's more comparable to a web app's html templater than a syntactic macro system like Lisp's.
It doesn't strictly have a 1-1 relationship because of macros themselves. They're Turing complete, so the same macro can expand into different ASTs based on user input during compilation, presence of any files on the hard drive or even moon phases, so I have to say that this relationship is much more complicated than a simple 1-1. For very simple functions like (lambda (x) (* x x)) this is true, but macros' power greatly complicates it.
Re:How to properly use macros in C
by dangerbird2 on Tuesday December 12, 2017 @02:47PM
(#15908823)
I should have said a read and macroexpanded lisp source has a 1-1 relationship with the AST.
As an aside, the bigger distinction between something like C++ template metaprogramming and Lisp metaprogramming is that while C++ uses a template language completely orthogonal to the runtime language, Lisp macros is nothing more than Lisp code executed at macroexpand-time rather than eval-time.
But again, Lisps generally have more powerful macros than C does - they allow for arbitrary compile-time computation.