Queue/Usage: Difference between revisions

Content added Content deleted
(replace Template:BoxImage with wiki markup)
(Added Erlang)
Line 201:
 
E also has queues in the standard library such as <code>&lt;import:org.erights.e.examples.concurrency.makeQueue></code>, but they are designed for concurrency purposes and do not report emptiness but rather return a promise for the next element.
 
=={{header|Erlang}}==
All functions, from the shell:
<lang Erlang>
1> Q = fifo:new().
{fifo,[],[]}
2> fifo:empty(Q).
true
3> Q2 = fifo:push(Q,1).
{fifo,[1],[]}
4> Q3 = fifo:push(Q2,2).
{fifo,[2,1],[]}
5> fifo:empty(Q3).
false
6> fifo:pop(Q3).
{1,{fifo,[],[2]}}
7> {Popped, Q} = fifo:pop(Q2).
{1,{fifo,[],[]}}
8> fifo:pop(fifo:new()).
** exception error: 'empty fifo'
in function fifo:pop/1
 
</lang>
Crashing is the normal expected behavior in Erlang: let it crash, a supervisor will take responsibility of restarting processes, or the caller will take care of it. Only program for the successful cases.
 
=={{header|Fortran}}==