Jump to content

Stack: Difference between revisions

1,183 bytes added ,  1 year ago
→‎{{header|Diego}}: Added Diego entry
(→‎{{header|Diego}}: Added Diego entry)
Line 2,505:
if stack: #empty lists are falsy
error #this stack should be empty now!</lang>
 
=={{header|Diego}}==
Diego has a <code>stack</code> object and posit:
<lang diego>set_ns(rosettacode)_me();
 
add_stack({int},a)_values(1..4); // 1,2,3,4 (1 is first/bottom, 4 is last/top)
with_stack(a)_pop(); // 1,2,3
with_stack(a)_push()_v(5,6); // 1,2,3,5,6
 
add_var({int},b)_value(7);
with_stack(a)_push[b]; // 1,2,3,5,6,7
 
with_stack(a)_pluck()_at(2); // callee will return `with_stack(a)_err(pluck invalid with stack);`
 
me_msg()_stack(a)_top(); // "7"
me_msg()_stack(a)_last(); // "7"
me_msg()_stack(a)_peek(); // "7"
 
me_msg()_stack(a)_bottom(); // "1"
me_msg()_stack(a)_first(); // "1"
me_msg()_stack(a)_peer(); // "1"
 
me_msg()_stack(a)_isempty(); // "false"
with_stack(a)_empty();
with_stack(a)_msg()_isempty()_me(); // "true" (alternative syntax)
 
me_msg()_stack(a)_history()_all(); // returns th entire history of stack 'a' since its creation
 
reset_ns[];</lang>
<code>stack</code> is a derivative of <code>array</code>, so arrays can also be used as stacks.
 
=={{header|E}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.