简体   繁体   English

哈希标志在erlang中做了什么?

[英]What does the hash sign do in erlang?

What does the hash sign do in erlang? 哈希标志在erlang中做了什么?

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

它们与记录一起使用。

Just for completeness (in case someone googles "Erlang Hash"): 只是为了完整(如果有人谷歌“Erlang哈希”):

The hash symbol can also be used to define an integer with an arbitrary base , as in 16#deadbeef = 3735928559. 哈希符号也可用于定义具有任意基数整数 ,如16#deadbeef = 3735928559.

They are related to Records in Erlang. 它们与Erlang中的Records有关。 Infact every operation like creation,accessing and updating records in Erlang are done using # http://20bits.com/articles/erlang-an-introduction-to-records/ 事实上,在Erlang中创建,访问和更新记录等每个操作都是使用#http://20bits.com/articles/erlang-an-introduction-to-records/完成的。

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}.

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. 除了作为前面的答案指出的数字记录和基本表示的语法的一部分,从Erlang R17,它们也用于地图。 Map is a new key-value datatype introduced in R17 and they are expressed as: #{ Key => Value, ... } Map是R17中引入的一种新的键值数据类型,它们表示为:#{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. 但是,在候选版本1中,似乎并未实现所描述的所有功能。

The Hash sign is used to work with records in erlang as noted by other answers. 哈希符号用于处理erlang中的记录,如其他答案所述。 Here is an article that explains the syntax in a bit more detail. 这篇文章更详细地解释了语法。 http://www.techtraits.com/Programming/2011/06/11/records-in-erlang/ http://www.techtraits.com/Programming/2011/06/11/records-in-erlang/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM