Stack: Difference between revisions

709 bytes added ,  15 years ago
Added perl and prolog
(Added perl and prolog)
Line 607:
end;
</lang>
 
=={{header|Perl}}==
Perl comes prepared to treat its lists as stacks, giving us the push and pop functions for free. To add empty, we basically give a new name to "not":
 
<lang perl>sub empty{ not @_ }</lang>
 
=={{header|Prolog}}==
Prolog is a particularly silly language to implement stack functions in, as the built-in lists can be treated as stacks in an ad hoc manner. Nonetheless, in the name of completeness:
 
<lang prolog>% push( ELEMENT, STACK, NEW )
% True if NEW is [ELEMENT|STACK]
push(ELEMENT,STACK,[ELEMENT|STACK]).
 
% pop( STACK, TOP, NEW )
% True if TOP and NEW are head and tail, respectively, of STACK
pop([TOP|STACK],TOP,STACK).
 
% empty( STACK )
% True if STACK is empty
empty([]).</lang>
 
=={{header|Python}}==
Anonymous user