[erlang-questions] Using a queue
Tue Aug 26 02:17:39 CEST 2008
On Tue, Aug 26, 2008 at 12:53 AM,
> I'm trying to use the queue module in Erlang by trying it out in the
> console. Here is what I tried and here are the results:
> 34> T1 = queue:new().
> 35> queue:in("foo", T1).
> 36> queue:in("bar", T1).
> What confuses me here is that I expected foo and bar to be somehow
> next to one another after inserting bar. Why is it that it's only foo?
You are performing all operations on the original queue, T1. You need
to assign the return value of each queue operation to something as
this is the new queue.
Eshell V5.6.1 (abort with ^G)
1> Q1 = queue:new().
2> Q2 = queue:in("foo", Q1).
3> Q3 = queue:in("bar", Q2).
> Also, I have another question. I would like a linked list in Erlang
> (similar to the STL list class in C++), is there something like that?
> It would be also nice if the individual elements in the said list
> could be accessed in a similar fashion as an array :) (don't know if
> this is possible).
As far as I know, the closest thing to the stl list in erlang is the
built in list type. You can use lists:nth(I, List) to emulate array
random access, or just use the 'array' API.
More information about the erlang-questions