[erlang-questions] Using a queue

yoursurrogategod@REDACTED yoursurrogategod@REDACTED
Tue Aug 26 02:53:17 CEST 2008


Ok, based on your suggestions, here is what I have.

Eshell V5.5.5  (abort with ^G)
1> Q1 = queue:new().
{[],[]}
2> Q2 = queue:in("foo", Q1).
{["foo"],[]}
3> Q3 = queue:in("bar", Q2).
{["bar"],["foo"]}
4> Q4 = queue:in("blah", Q3).
{["blah","bar"],["foo"]}
5> Q5 = queue:in("stuff", Q4).
{["stuff","blah","bar"],["foo"]}
6> Q6 = queue:out(Q5).
{{value,"foo"},{["stuff","blah"],["bar"]}}
7> Q7 = queue:in("stuff1", Q6).

=ERROR REPORT==== 25-Aug-2008::20:23:40 ===
Error in process <0.31.0> with exit value: {badarg,[{queue,in,
["stuff1",{{value,"foo"},{["stuff","blah"],["bar"]}}]},
{erl_eval,do_apply,5},{erl_eval,expr,5},{shell,exprs,6},
{shell,eval_loop,3}]}

** exited: {badarg,[{queue,in,
                           ["stuff1",
                            {{value,"foo"},{["stuff","blah"],
["bar"]}}]},
                    {erl_eval,do_apply,5},
                    {erl_eval,expr,5},
                    {shell,exprs,6},
                    {shell,eval_loop,3}]} **

For some reason, when I tried to add on to Q7 after removing a value,
it crashed. One thing that I discovered was when I did > Q6., I got
the below:

{{value,"foo"},{["stuff","blah"],["bar"]}}

I managed to get at the list that contains stuff and blah (which is a
little odd).


On Aug 25, 8:17 pm, "Colm Dougan" <colm.dou...@REDACTED> wrote:
> On Tue, Aug 26, 2008 at 12:53 AM, yoursurrogate...@REDACTED
>
> <yoursurrogate...@REDACTED> wrote:
> > 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).
> > {["foo"],[]}
> > 36> queue:in("bar", T1).
> > {["bar"],[]}
>
> > 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.
>
> e.g. :
>
> Eshell V5.6.1  (abort with ^G)
> 1> Q1 = queue:new().
> {[],[]}
> 2> Q2 = queue:in("foo", Q1).
> {["foo"],[]}
> 3> Q3 = queue:in("bar", Q2).
> {["bar"],["foo"]}
>
>
>
> > 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.
>
> Colm
> _______________________________________________
> erlang-questions mailing list
> erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list