5 ms·
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++). This is false
by phoe-krk 9y ago
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++).
This is false. Lisp is a language, or rather, a family of languages, where macros play a giant role, and the author does not seem to mention them.
But again, Lisps generally have more powerful macros than C does - they allow for arbitrary compile-time computation.
- Stratoscope 9y agoMore 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.*
- phoe-krk 9y agoThanks, TIL.
- naavis 9y agoMacros are fairly common in Rust too.
- dangerbird2 9y agoLisp 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.
- phoe-krk 9y agoIt 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.
- dangerbird2 9y agoI 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.
- kazinator 9y agoA Lisp form with unexpanded macros has abstract syntax; the unexpanded macro forms are AST material.
- kazinator 9y agoPeople 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.
- angry_octet 9y agoWhile your comment provides no evidence in support of its contention, it does support the notion that Lisp programmers have excessive hubris.