[erlang-questions] Using a queue

Colm Dougan colm.dougan@REDACTED
Tue Aug 26 03:12:08 CEST 2008


On Tue, Aug 26, 2008 at 1:53 AM, yoursurrogategod@REDACTED
<yoursurrogategod@REDACTED> wrote:
> 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}]}

The documentation for queue:out says :

"Removes the item at the front of queue Q1. Returns the tuple {{value,
Item}, Q2}, where Item is the item removed and Q2 is the resulting
queue. If Q1 is empty, the tuple {empty, Q1} is returned."

   http://www.erlang.org/doc/man/queue.html

So :

   Q6 = queue:out(Q5)

Should have been :

   {Val1, Q6} = queue:out(Q5).

Colm



More information about the erlang-questions mailing list