RosettaCodeData/Task/Queue-Usage/Diego/queue-usage.diego

32 lines
1.2 KiB
Plaintext

set_ns(rosettacode)_me();
add_queue({int},q)_values(1..4); // 1,2,3,4 (1 is first/bottom, 4 is last/top)
with_queue(q)_pop(); // 2,3,4
with_queue(q)_dequeue(); // 3,4
with_queue(q)_enqueue(5); // 3,4,5
with_queue(q)_push()_v(6,7); // 3,4,5,6,7
add_var({int},b)_value(8);
with_queue(q)_push[b]; // 3,4,5,6,7,8
with_queue(q)_pluck()_at(2); // callee will return `with_queue(q)_err(pluck invalid with queue);`
me_msg()_queue(q)_top(); // "8"
me_msg()_queue(q)_last(); // "8"
me_msg()_queue(q)_peek(); // "8"
me_msg()_queue(q)_bottom(); // "3"
me_msg()_queue(q)_first(); // "3"
me_msg()_queue(q)_peer(); // "3"
me_msg()_queue(q)_isempty(); // "false"
with_queue(q)_empty();
with_queue(q)_msg()_isempty()_me(); // "true" (alternative syntax)
with_queue()_pop(); // callee will return `with_queue(q)_err(pop invalid with empty queue);`
me_msg()_queue(q)_history()_all(); // returns the entire history of queue 'q' since its creation
reset_namespace[];