Stack: Difference between revisions

2,110 bytes added ,  1 month ago
m
(→‎{{header|Lambdatalk}}: adding lambdatalk task)
 
(8 intermediate revisions by 7 users not shown)
Line 1,374:
exit /b 0</syntaxhighlight>
 
=={{header|BBC BASIC}}==
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> STACKSIZE = 1000
Line 2,591 ⟶ 2,592:
? s.empty()
# value: true</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
stack[] = [ ]
proc push v . .
stack[] &= v
.
func pop .
lng = len stack[]
if lng = 0
return 0
.
r = stack[lng]
len stack[] -1
return r
.
func empty .
return if len stack[] = 0
.
push 2
push 11
push 34
while empty = 0
print pop
.
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 2,669 ⟶ 2,696:
var stack := new system'collections'Stack();
stack.push:(2);
var isEmpty := stack.Length == 0;
Line 3,468 ⟶ 3,495:
top value: four
four popped. stack: [3]
</pre>
 
=={{header|GDScript}}==
In GDScript there is built-in Array class, that implements either 'push', 'pop', 'top' and 'empty' methods. Method names are:
<ul>
<li>push -> push_back</li>
<li>pop -> pop_back</li>
<li>top -> back</li>
<li>empty -> is_empty</li>
</ul>
<syntaxhighlight lang="gdscript">
extends Node2D
 
func _ready() -> void:
# Empty stack creation.
var stack : Array = []
# In Godot 4.2.1 nothing happens here.
stack.pop_back()
if stack.is_empty():
print("Stack is empty.")
stack.push_back(3)
stack.push_back("Value")
stack.push_back(1.5e32)
print(stack)
print("Last element is: " + str(stack.back()))
stack.pop_back()
print(stack)
print("Last element is: " + str(stack.back()))
if not stack.is_empty():
print("Stack is not empty.")
return
</syntaxhighlight>
{{out}}
<pre>
Stack is empty.
[3, "Value", 149999999999999999042044051849216]
Last element is: 149999999999999999042044051849216
[3, "Value"]
Last element is: Value
Stack is not empty.
</pre>
 
Line 3,474 ⟶ 3,546:
 
Of course, these stack semantics are not ''exclusive''. Elements of the list can still be accessed and manipulated in myriads of other ways.
 
If you need exclusive stack semantics, you can use the <code>java.util.Stack</code> class, as demonstrated in the [[Stack#Java|Java]] example.
 
<syntaxhighlight lang="groovy">def stack = []
assert stack.empty
Line 5,866 ⟶ 5,941:
</pre>
 
=={{header|RPL}}==
The RPL interpreter is based on a stack, with which the user interacts.
*the push operation is performed by the <code>DUP</code> instruction
*the pop operation by <code>DROP</code>
*<code>DEPTH</code> provides the stack size. To test the emptiness of the stack, the following program can be created as an user-defined instruction:
≪ DEPTH NOT ≫ 'EMPTY?' STO
=={{header|Ruby}}==
Using an Array, there are already methods Array#push, Array#pop and Array#empty?.
Line 6,563 ⟶ 6,644:
S pop 4 ;# ==> d c b a
S size ;# ==> 0</syntaxhighlight>
 
=={{header|Uiua}}==
 
<syntaxhighlight lang="Uiua">
[3] # Since UIUA is a stack language, everything is pushed on the stack
x ← # stores the top of the stack into the variable x
? # ? checks the stack, it is now empty
 
</syntaxhighlight>
 
 
 
=={{header|UnixPipes}}==
Line 6,981 ⟶ 7,073:
{{libheader|Wren-seq}}
This uses the Stack class in the above module.
<syntaxhighlight lang="ecmascriptwren">import "./seq" for Stack
 
var s = Stack.new()
1

edit