美文网首页
Clojure macro

Clojure macro

作者: 我要走多远 | 来源:发表于2015-03-11 21:23 被阅读70次

At first, I want to add before/after to FacthCheck(Julia test framework).

But I don't understand macro well and there is soo little material about Julia macro,

and Clojure is similar to Julia, so I try to learn Clojure macro.

The macro

pass some expressions and return a single expression out

How it works

Clojure-compile-time-and-run-time

Clojure is a compiled language.

The compiler reads source files or strings, produces data structures (aka the AST)

and performs macroexpansion.

Macros are evaluated at compile time and produce modified data structures

that are compiled to the JVM bytecode.

That bytecode is executed at run time.

'macro transform an expression into something else, before runtime'

How to write macro

When a macro is called, it will generate code.

1. write example about how the macro is used

2. write the wishful macro result done

3. decompose the problem

same procedure as you write other kind of code,

but those should be under concern:

1. the args passed are "expression"

2. the output is one expression.

3. it is cool to compose the expression.

4. take care "Anaphora" and "Hygiene"

How to use macro

' quote

` syntax-quoting  # foo# gen symbol auto

~ unquote  # causes a quoted form to be evaluated

~@ unquote-splice

`'~v evalue v, and quote it, then solve it in current environment

Quote vs Syntax-quoting

http://blog.8thlight.com/colin-jones/2012/05/22/quoting-without-confusion.html

1. with namespace

2. will eval the from in an unquote

3. can generate symbol by "foo#"

tricks:

~'c without the namespace symbol c

~`c with the namespace symbol c

相关文章

  • Clojure macro

    At first, I want to add before/after to FacthCheck(Julia ...

  • clojure宏魔法

    了解clojure的宏(macro)之后,真真是个好东西呀。让你可以随心所欲,设计自己的语法,甚至创造新的语言。而...

  • clojure macro 宏的一点浅见

    工作之余 站在半山腰 清风吹来, 大西北干燥的凛冽,似乎要吹进骨子里,心中升起一种印在灵魂深处的无法言说的亲切感....

  • Clojure 脚本

    Clojure 语法 https://www.w3cschool.cn/clojure/clojure_basic...

  • clojure 内部

    The Life of a Clojure Expression: A Quick Tour of Clojure...

  • Docker下安装 Clojure

    Docker环境下Clojure 搜索 Clojure 镜像,下载,并在命令行下启动镜像 使用 Clojure 的...

  • [job]Clojure Jobs | ClojureDocs

    Clojure Jobs | ClojureDocs - Community-Powered Clojure Do...

  • Clojure 编译器实现

    准备Clojure源代码阅读环境 获取clojure源代码clojure项目托管在github,运行以下命令获取源...

  • 如何高效地学习编程语言

    这是Clojure好书《Clojure for the Brave and True》作者 Daniel Higg...

  • Clojure学习资料汇总

    注:转自《Clojure学习资料汇总》 官方文档 中文资料(强烈推荐):clojure入门教程clojure文档翻...

网友评论

      本文标题:Clojure macro

      本文链接:https://www.haomeiwen.com/subject/zkhbxttx.html