Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the hash sign do in erlang?

Tags:

erlang

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).
....
.
like image 840
Usman Ismail Avatar asked May 20 '11 19:05

Usman Ismail


4 Answers

They're used alongside records.

like image 69
Rafe Kettler Avatar answered Nov 13 '22 18:11

Rafe Kettler


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.
like image 25
kay Avatar answered Nov 13 '22 17:11

kay


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/

like image 8
niting112 Avatar answered Nov 13 '22 19:11

niting112


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}.
like image 4
Fabio Avatar answered Nov 13 '22 17:11

Fabio