struct::stack(3tcl)
π struct::stack β the Tcl Data Structures manual, but make it cute π
okay bestie, sit down, hydrate, because we're learning about struct::stack from the Tcl Data Structures manual and it's genuinely so much fun. this is the struct::stack(3tcl) page and yes it's giving "finite stacks, but make it iconic" β¨
π NAME π
struct::stack β create and manipulate stack objects. that's it, that's the whole vibe. π«Ά
β¨ SYNOPSIS β¨
no cap, here's the whole shape of it:
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 all those little commands. they're like a friend group fr fr π
πΈ DESCRIPTION πΈ
so, the ::struct namespace is where all the commands for processing finite stacks live. it exports exactly one command β ::struct::stack β and literally every bit of functionality here is reachable through a subcommand of that one command. one queen, many talents. π
π‘ note, bestie: as of version 1.3.3 of this package, there's a critcl based C implementation available. but β and this is important β that implementation requires Tcl 8.4 to run. iykyk.
the ::struct::stack command creates a brand new stack object with an associated global Tcl command whose name is stackName. you use that command to invoke all the various operations on the stack. its general form is:
stackName option ?arg arg ...?
option and the args determine the exact behavior of the command. and these are the commands possible for stack objects β buckle up, there's a lot and we love that for us:
stackName clearβ remove all items from the stack. like, gone. bye. π§ΉstackName destroyβ destroy the stack, including its storage space and its associated command. it's not just leaving the party, it's deleting the group chat. πstackName getβ returns the whole contents of the stack as a list, and does not remove them from the stack. look, don't touch. πstackName getrβ a variant ofget, but it returns the contents in reversed order. β¨stackName peek ?count?β return the topcountitems of the stack, without removing them from the stack. ifcountisn't specified, it defaults to 1. ifcountis 1, the result is a simple string; otherwise it's a list. if specified,countmust be greater than or equal to 1. and if there aren't 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. πstackName trim ?newsize?β shrinks the stack to contain at mostnewsizeelements, and returns a list containing the elements which were removed. if the stack is already at the specified size, or smaller, nothing is done β and in that case the result is the empty list. lowkey polite of it. πstackName trim* ?newsize?β a variant oftrimwhich performs the shrinking, but does not return the removed elements. silent, mysterious, main character energy. πstackName pop ?count?β return the topcountitems of the stack, and remove them from the stack. ifcountisn't specified, it defaults to 1. ifcountis 1, the result is a simple string; otherwise it's a list. if specified,countmust be greater than or equal to 1. and if there aren't enough items on the stack to fulfil the request, this command will throw an error. same energy aspeek, but it actually takes the items with it. π«£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, always has. πstackName sizeβ return the number of items on the stack. the headcount. the attendance list. π
π BUGS, IDEAS, FEEDBACK π
ngl, this document β and the package it describes β will undoubtedly contain bugs and other problems. it's giving "we're all human." so please report them in the category struct :: stack of the Tcllib Trackers:
http://core.tcl.tk/tcllib/reportlist
and please also report any ideas for enhancements you may have for either the package and/or the documentation. we love a glow-up suggestion. π
when proposing code changes, please provide unified diffs, i.e. the output of diff -u. that's the standard, no substitutions. β¨
β οΈ 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. do it that way, fr fr. π«Ά
π₯ KEYWORDS π₯
- graph
- matrix
- queue
- tree
(not me noticing stack isn't in its own keyword list β iconic behavior honestly π)
π CATEGORY π
Data structures
and that's the whole page, bestie!! π you now know every single option, argument, default, error case and caveat, and you did it with style. slay. π¦
this was tcllib version 1.5.4, dated struct::stack(3tcl) β mwah, go push something onto a stack and feel powerful. π β¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms