erlang 中的哈希符号有什么作用?

发布于 2024-11-08 07:23:54 字数 286 浏览 0 评论 0原文

erlang 中的哈希符号有什么作用?

record_to_string(#roster{us = {User, _Server},
         jid = JID,
         name = Name,
         subscription = Subscription,
         ask = Ask,
         askmessage = AskMessage}) ->
Username = ejabberd_odbc:escape(User).
....
.

What does the hash sign do in erlang?

record_to_string(#roster{us = {User, _Server},
         jid = JID,
         name = Name,
         subscription = Subscription,
         ask = Ask,
         askmessage = AskMessage}) ->
Username = ejabberd_odbc:escape(User).
....
.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

鹿港巷口少年归 2024-11-15 07:23:54

它们与记录一起使用。

They're used alongside records.

书信已泛黄 2024-11-15 07:23:54

只是为了完整性(以防有人在谷歌上搜索“Erlang Hash”):

哈希符号也可以用于定义 具有任意基数的整数,如

16#deadbeef = 3735928559.

Just for completeness (in case someone googles "Erlang Hash"):

The hash symbol can also be used to define an integer with an arbitrary base, as in

16#deadbeef = 3735928559.
心房的律动 2024-11-15 07:23:54

它们与 Erlang 中的记录相关。事实上,Erlang 中的创建、访问和更新记录等每个操作都是使用 # http: //20bits.com/articles/erlang-an-introduction-to-records/

They are related to Records in Erlang. Infact every operation like creation,accessing and updating records in Erlang are done using # http://20bits.com/articles/erlang-an-introduction-to-records/

岁月苍老的讽刺 2024-11-15 07:23:54

如果一条记录是这样定义的:

-record(record_name, {first_field, second_field}).

您可以通过多种方式使用哈希来访问该记录,其中:

% create a new record and put it in a variable
Record = #record_name{first_field = 1, second_field = 2},

% get only the second_field of Record
Field = Record#record_name.second_field,

% create a new record from Record, but with a different first_field
Record2 = Record#record_name{first_field = 5}.

If a record is defined like this:

-record(record_name, {first_field, second_field}).

You can use the hash to access the record in various ways, among which:

% create a new record and put it in a variable
Record = #record_name{first_field = 1, second_field = 2},

% get only the second_field of Record
Field = Record#record_name.second_field,

% create a new record from Record, but with a different first_field
Record2 = Record#record_name{first_field = 5}.
時窥 2024-11-15 07:23:54

正如之前的答案所指出的,它们不仅是记录语法和数字基本表示的一部分,从 Erlang R17 开始,它们还用于映射。 Map是R17中引入的新的键值数据类型,它们表示为:#{Key =>;值,... }

我认为地图上最好的信息来源是此链接。然而,在候选版本 1 中,似乎并未实现其中描述的所有功能。

As well as being part of the syntax for records and base denotation in numbers as previous answers have pointed out, as of Erlang R17, they are also used for maps. Map is a new key-value datatype introduced in R17 and they are expressed as: #{ Key => Value, ... }

I think the best source of information on maps is this link. However, in release candidate 1 it seems not all functionality described there is implemented.

怀里藏娇 2024-11-15 07:23:54

正如其他答案所述,哈希符号用于处理 erlang 中的记录。这是一篇更详细地解释语法的文章。
http://www.techtraits.com/Programming/2011/ 06/11/erlang 记录/

The Hash sign is used to work with records in erlang as noted by other answers. Here is an article that explains the syntax in a bit more detail.
http://www.techtraits.com/Programming/2011/06/11/records-in-erlang/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文