struct::stack(n)
π struct::stack β the manual, but make it make sense π
tcllib Β· version 1.5.4 Β· from the Tcl Data Structures corner of the world π¦
okay bestie, sit down, hydrate, because today we're talking about struct::stack β and yes, that's the manual name, that's the whole vibe, we're doing stacks today and we're doing them correctly. β¨
πΈ NAME πΈ
struct::stack β Create and manipulate stack objects π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require struct::stack ?1.5.4?
stackName option ?arg arg ...?
stackName clear
stackName destroy
stackName get
stackName getr
stackName peek ?count?
stackName peekr ?count?
stackName trim ?newsize?
stackName trim* ?newsize?
stackName pop ?count?
stackName push item ?item...?
stackName size
look at her. a whole repertoire. an icon. π
π DESCRIPTION π
So, the ::struct namespace is out here holding a bunch of commands for processing finite stacks. That's the whole thing. That's the job. π«Ά
It exports exactly one command: ::struct::stack. And every single bit of functionality that exists in this package? You reach it through a subcommand of that one command. One command to rule them all, no cap. π
π Note: as of version 1.3.3 of this package, a critcl based C implementation is available. This implementation however requires Tcl 8.4 to run. (yes, older Tcl. she's built different, literally.)
The ::struct::stack command creates a brand new stack object with an associated global Tcl command whose name is stackName. You then use that command to invoke all the various operations on your stack. Its general form is:
stackName option ?arg arg ...?
option and the args are what decide the exact behavior of the command. And here's every single command a stack object understands, no skipping, no summarising, we are thorough in this household: π§
stackName clearβ Remove all items from the stack. poof. gone. empty girl summer. πstackName destroyβ Destroy the stack, including its storage space and associated command. it's not just clearing, bestie, it's ending it. πstackName getβ Returns the whole contents of the stack as a list, without removing them from the stack. look, don't touch. πstackName getrβ A variant ofget, which returns the contents in reversed order. the r stands for r-reversed, obviously, keep up. β¨stackName peek ?count?β Return the top count items of the stack, without removing them from the stack. If count is not specified, it defaults to1. If count is1, the result is a simple string; otherwise, it is a list. If specified, count must be greater than or equal to1. If there are not enough items on the stack to fulfil the request, this command will throw an error. πstackName peekr ?count?β A variant ofpeek, which returns the items in reversed order. same peek energy, opposite direction. π¦stackName trim ?newsize?β Shrinks the stack to contain at most newsize elements and returns a list containing the elements which were removed. Nothing is done if the stack is already at the specified size, or smaller. In that case the result is the empty list. a lil haircut, and you get the clippings back. βοΈstackName trim* ?newsize?β A variant oftrimwhich performs the shrinking, but does not return the removed elements. same haircut, no clippings, we don't talk about them. πstackName pop ?count?β Return the top count items of the stack, and remove them from the stack. If count is not specified, it defaults to1. If count is1, the result is a simple string; otherwise, it is a list. If specified, count must be greater than or equal to1. If there are not enough items on the stack to fulfil the request, this command will throw an error. the classic. the moment. πstackName push item ?item...?β Push the item or items specified onto the stack. If more than one item is given, they will be pushed in the order they are listed. (order matters, bestie, do not freestyle it.) π₯stackName sizeβ Return the number of items on the stack. just the number. no notes. β
π BUGS, IDEAS, FEEDBACK π
okay so, real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. yes. we know. it's giving "humbling". π
Please report such in the category struct :: stack of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist.
Please also report any ideas for enhancements you may have for either the package and/or the documentation. we want them. we want the ideas. π«Ά
When proposing code changes, please provide unified diffs, i.e. the output of diff -u.
β οΈ Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. that's the way. that's the path. π§
π KEYWORDS π
graph, matrix, queue, tree
(yes the keywords for the stack page are those. we don't ask questions, we just vibe check and move on. π)
π CATEGORY π
Data structures
and that's the whole page, bestie!! you ate. go build something with a stack in it, and remember: push responsibly, pop dramatically. π β¨
with love from the tcllib crew, package version 1.5.4, dated 1.5.4, and honestly? iconic of them. struct::stack(n). periodt. ππ
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms