本文介绍了Erlang:问号语法是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Erlang语法中的问号是什么意思?

What does the question mark in Erlang syntax mean?

例如:

Json = ?record_to_json(artist, Artist).

源的完整上下文可以在。

The full context of the source can be found here.

推荐答案

Erlang使用问号来标识。例如考虑下面的代码:

Erlang uses question mark to identify macros. For e.g. consider the below code:

-ifdef(debug).
-define(DEBUG(Format, Args), io:format(Format, Args)).
-else.
-define(DEBUG(Format, Args), void).
-endif.

如文档所述,

此代码段定义了一个名为 DEBUG 的宏,该宏将替换为在 debug时打印字符串的调用在编译时设置。然后在下面的代码中使用该宏:

This snippet defines a macro called DEBUG that is replaced with a call to print a string if debug is set at compile time. The macro is then used in the following code thus:

?DEBUG("Creating ~p for N = ~p~n", [First, N]),

如果调试已设置。因此,只有设置 debug 时,您才能看到调试消息。

This statement is expanded and replaced with the appropriate contents if debug is set. Therefore you get to see debug messages only if debug is set.

更新

感谢:

这篇关于Erlang:问号语法是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 12:57