views:

240

answers:

3

What I wanted was a way to pass arguments into functions which resembled a ruby hash map. Although maybe this is a bad fit for Erlang, I'm not sure yet

In Ruby I often used hashes like:

{"a"=>100, "b"=>200}

: What is the closest thing in Erlang?

Update: I have since found this:

http://20bits.com/articles/erlang-an-introduction-to-records/

Is using records a good candidate?

+3  A: 

Here You are: dict - Key-Value Dictionary

Post scriptum: I have googled this within 30s so I think You could avoid this asking question ;-)

Edit: To defend my answer:

from_list(List) -> Dict

Types:
List = [{Key, Value}]
Dict = dictionary()

This function converts the key/value list List to a dictionary.

This is a quotation from my link. So You can create hashes exactly the same way as when You use proplists.

Dejw
I did google it and there is nothing remotely similar syntactically to in the web page you described:{"a"=>100, "b"=>200}
Zubair
I thought You are asking about functional similarity, not syntactical, because I think ridiculous is to search for similar syntax, only in order to write code which looks like the same as in other language.
Dejw
Yes, your probably right. Its just that often when I look at erlang function calls, its hard to know exactly what each parameter is for, and I always liked Ruby hashes. But yes, I'm probably askign the wrong question. Thanks
Zubair
+10  A: 

proplists, dicts, or gb_trees.

Zed
proplists seem to have the nicest similar syntax. Thanks Zed
Zubair
proplists may be similar in syntax, but it is not a hash. Linear lookup time but constant insert though.Edit: I should read the question, you really wanted the syntax. =)
psyeugenic
linear lookup can be way faster for hashes with only a handful of elements...
Zed
With lists of more than 20 elements, ETS tables are faster.
Adam Lindberg
+3  A: 

ETS and DETS tables are true hash tables unlike a dict. DETS are for disks storage while ETS are in memory. They are the building blocks for the Mnesia database.

Tristan Sloughter
But are ETS or DETS any use for passing in paramters to a function?
Zubair
Sure -- but I'm not sure what you mean. Note, however, they are not immutable structures, they do not return a new modified copy after a 'put'. So they can be dangerous. But if you for sure need the speed of a hash and large size they are the way to go.
Tristan Sloughter