2011-05-20 31 views
10

散列符號在erlang中做了什麼?散列符號在erlang中做了什麼?

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

回答

26

它們與records一起使用。

+1

謝謝,符號總是很難谷歌。 – 2011-05-20 20:01:57

+1

查看http://learnyousomeerlang.com/a-short-visit-to-common-data-structures#records和http://www.erlang.org/doc/reference_manual/records.html查看完整內容說明。 – 2011-05-22 18:42:35

11

只是爲了完整性(萬一有人網上搜尋「二郎哈希」):

散列符號也可以用來定義integer with an arbitrary base ,如在16#deadbeef = 3735928559.

1

哈希標記用於處理erlang中的記錄,如其他答案所述。這裏有一篇文章更詳細地解釋了語法。 http://www.techtraits.com/Programming/2011/06/11/records-in-erlang/

+3

歡迎來到SO!雖然這在理論上回答了 的問題,[這將是更可取的](http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers/ 8259#8259)在這裏包含答案的基本部分,並提供僅供參考的鏈接。 – 2011-06-13 09:03:32

2

如果一個記錄被這樣定義:

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

我知道這是一個回答問題,但我把它放在這裏供將來參考,因爲我前一段時間需要它,只找到鏈接,而不是自包含的答案。 鏈接是有用的,但正如另一個評論指出,不應該構成一個完整的答案。 – Fabio 2013-09-07 21:39:42

2

在前面的答案中已經指出了數字記錄和基數表示的語法,從Erlang R17開始,它們也用於地圖。 Map是R17中引入的新鍵值數據類型,它們表示爲:#{Key => Value,...}

我認爲地圖上最好的信息來源是this link。但是,在發佈候選1中,似乎並非所有描述的功能都已實現。