What does the hash sign do in erlang?开发者_Go百科
record_to_string(#roster{us = {User, _Server},
jid = JID,
name = Name,
subscription = Subscription,
ask = Ask,
askmessage = AskMessage}) ->
Username = ejabberd_odbc:escape(User).
....
.
They're used alongside records.
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.
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/
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. 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.
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/
精彩评论