Scala Macros可以直接对程序进行修改。 , demos) 18 19 lazy val macros = project.in(file("macros")).settings(commonSettings : _*) 20 21 lazy dependsOn(macros),因为我们会把所有macros定义文件放在macros目录下。 代码放在macros目录下的MacrosLibrary.scala里。首先必须import macros和Context。 Scala Def Macros还提供了Extractor Macros,结合Scala String Interpolation和模式匹配来提供compile time的extractor object
官方解释: You can sort of think of procedural macros as functions from an AST(抽象语法树) to another AST. — The
Elixir Macros 系列文章译文 [1] (译) Understanding Elixir Macros, Part 1 Basics [2] (译) Understanding Elixir Macros, Part 2 - Micro Theory [3] (译) Understanding Elixir Macros, Part 3 - Getting into the AST [4] (译) Understanding Elixir Macros, Part 4 - Diving Deeper [5] (译) Understanding Elixir Macros, Part 5 这是讨论宏 (Macros) 微系列文章的第一篇. 原文:https://www.theerlangelist.com/article/macros_1
Elixir Macros 系列文章译文 [1] (译) Understanding Elixir Macros, Part 1 Basics [2] (译) Understanding Elixir Macros, Part 2 - Micro Theory [3] (译) Understanding Elixir Macros, Part 3 - Getting into the AST [4] (译) Understanding Elixir Macros, Part 4 - Diving Deeper [5] (译) Understanding Elixir Macros, Part 5 - Reshaping the AST [6] (译) Understanding Elixir Macros, Part 6 - In-place Code Generation 原文 GitHub 原文: https://www.theerlangelist.com/article/macros_3
Elixir Macros 系列文章译文 [1] (译) Understanding Elixir Macros, Part 1 Basics [2] (译) Understanding Elixir Macros, Part 2 - Micro Theory [3] (译) Understanding Elixir Macros, Part 3 - Getting into the AST [4] (译) Understanding Elixir Macros, Part 4 - Diving Deeper [5] (译) Understanding Elixir Macros, Part 5 - Reshaping the AST [6] (译) Understanding Elixir Macros, Part 6 - In-place Code Generation 原文 GitHub 原文: https://www.theerlangelist.com/article/macros_4
Elixir Macros 系列文章译文 [1] (译) Understanding Elixir Macros, Part 1 Basics [2] (译) Understanding Elixir Macros, Part 2 - Micro Theory [3] (译) Understanding Elixir Macros, Part 3 - Getting into the AST [4] (译) Understanding Elixir Macros, Part 4 - Diving Deeper [5] (译) Understanding Elixir Macros, Part 5 - Reshaping the AST [6] (译) Understanding Elixir Macros, Part 6 - In-place Code Generation 原文 GitHub 原文: https://www.theerlangelist.com/article/macros_2
Elixir Macros 系列文章译文 [1] (译) Understanding Elixir Macros, Part 1 Basics [2] (译) Understanding Elixir Macros, Part 2 - Micro Theory [3] (译) Understanding Elixir Macros, Part 3 - Getting into the AST [4] (译) Understanding Elixir Macros, Part 4 - Diving Deeper [5] (译) Understanding Elixir Macros, Part 5 - Reshaping the AST [6] (译) Understanding Elixir Macros, Part 6 - In-place Code Generation 原文 GitHub 原文: https://www.theerlangelist.com/article/macros_5
Scalameta是根据scala语言规范SIP-28-29-Inline-Macros由零重新设计的Macros编程工具库。 这事动摇了我继续探讨的意愿:试想如果没了”Implicit Macros“,“Extractor Macros“这些模式,会损失多少理想有趣的编码方式。 我们可以把上次Def Macros的Macros Annotations示范例子在Scalameta里重新示范一遍来达到这样的目的。 与Def Macros运算原理相同,Scalameta的Macros扩展也是基于AST(abstract syntax tree)由编译器运算产生的,因此Macros申明必须先完成编译,所以我们还是沿用了上一篇讨论中的 直观上Macros编程简单了,实际上编写的Macros程序能更安全稳定的运行。
本书试图提炼Rust社区对Rust宏的知识集,目前还在完善中,欢迎添加PR和issue。
Elixir Macros 系列文章译文 [1] (译) Understanding Elixir Macros, Part 1 Basics [2] (译) Understanding Elixir Macros, Part 2 - Micro Theory [3] (译) Understanding Elixir Macros, Part 3 - Getting into the AST [4] (译) Understanding Elixir Macros, Part 4 - Diving Deeper [5] (译) Understanding Elixir Macros, Part 5 - Reshaping the AST [6] (译) Understanding Elixir Macros, Part 6 - In-place Code Generation 原文 GitHub 原文: https://www.theerlangelist.com/article/macros_6
既然 Babel 有了 Plugin 为什么又冒出了个 babel-plugin-macros? 所以才催生除了 babel-plugin-macros, 大家可以看这个 Issue: RFC - babel-macros 所以为 Babel 寻求一个零配置的机制是 babel-plugin-macros (查看awesome-babel-macros) 如何写一个 Babel Macro 所以,Babel Macro是如何运作的呢? 本文对‘宏’进行了深入的讨论,从 C 语言的文本替换宏到濒死的Sweet.js, 最后介绍了babel-plugin-macros. ,Babel Macro 可以做很多有意思的东西,查看《Awesome babel macros》。不过要谨记:显式好于隐式,清晰的代码优于简洁的代码
Rust 需要 proc-macros 2.0 吗? 毫无疑问,宏是 Rust 编程语言的一个重要特性。像 println!, lazy_static! rust 改进了声明性宏,但 Rust 也有 proc-macros(过程宏)。Proc-macros 本质上是将标记流转换为标记流的编译器的扩展。 这使得 proc-macros 在声明性宏无法处理的情况下非常强大和有用。文章为我们讲解了 proc-macros 的优劣,同时也给出了很棒的 proc-macros 代码。
但是运行时提示: ndk missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS 查找了一番, 没有找到直接的答案. 通过提示知道需要给cpp增加一个标识, 按照如下这样在gradle的 cppFlags 增加 "-D__STDC_CONSTANT_MACROS"即可. -> 'src/main/libs' cppFlags "-DTEST_CPP_FLAG2", "-DTEST_CPP_FLAG2", "-D__STDC_CONSTANT_MACROS
Result: OK 三、日志封装 ---- Google 中提供了一个很好的 log 封装头文件 , logging_macros.h , 很多官方示例中都使用这个头文件 ; #ifndef __SAMPLE_ANDROID_DEBUG_H
ES.33: If you must use macros, give them unique names ES.33:如果必须使用宏定义,命名要有唯一性 Reason(原因) Macros do not else's MYCHAR*/ #define ZCORP_CHAR /* Still evil, but less likely to clash */ Note(注意) Avoid macros However, there are billions of lines of code littered with macros and a long tradition for using and overusing macros. If you are forced to use macros, use long names and supposedly unique prefixes (e.g., your organization's
/ #define __STDC_FORMAT_MACROS #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS //common.h中的错误 #define __STDC_FORMAT_MACROS //timestamp.h中的错误 #endif
ES.31: Don't use macros for constants or "functions" ES.31:不要用宏定义常量或函数 Reason(原因) Macros are a major Macros don't obey the usual scope and type rules. Macros don't obey the usual rules for argument passing. Macros ensure that the human reader sees something different from what the compiler sees. Macros complicate tool building. 宏是错误的主要来源之一。宏不会遵守通常的范围和类型准则。宏也不会遵守参数传递准则。宏为人提供一个和编译器视角有些不同的视角。
-D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -DBUILD_EXAMPLES -I/data02/mingjie/bin -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -DBUILD_EXAMPLES -I/data02/mingjie/bin -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -DBUILD_EXAMPLES -I/data02/mingjie/bin -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -DBUILD_EXAMPLES -I/data02/mingjie/bin -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -DBUILD_EXAMPLES -I/data02/mingjie/bin
--more-->Kodeco文件自定义的说明如下:图片实现通过Customize text macros和Text macros reference可以看出,Xcode默认头部文字注释默认定义如下:/ FULLUSERNAME___ on ___DATE___.// ___COPYRIGHT___//然后参考Customizing the file header comment and other text macros in Xcode 9可以确定修改的步骤是:创建IDETemplateMacros.plist添加或修改Root对应的type为Dictionary然后参考Text macros reference中字段的含义 by 的用户名,又不想修改电脑用户名(可能会有风险),就可以通过最后一种方式修改,如下:图片参考Customizing the file header comment and other text macros in Xcode 9Customize text macrosText macros reference
ES.30: Don't use macros for program text manipulation ES.30: 不要使用宏进行程序中的文本操作 Reason(原因) Macros are Macros don't obey the usual scope and type rules. Macros ensure that the human reader sees something different from what the compiler sees. Often the desire to use fancy macros is a sign of an overly complex design. Also, # and ## encourages the definition and use of macros: 本规则也不鼓励使用#和##进行字符串的转换和链接。