struct::stack(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– 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 of get, 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 to 1. If count is 1, the result is a simple string; otherwise, it is a list. If specified, count must be greater than or equal to 1. If there are not enough items on the stack to fulfil the request, this command will throw an error. πŸ‘€
  • stackName peekr ?count? β€” A variant of peek, 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 of trim which 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 to 1. If count is 1, the result is a simple string; otherwise, it is a list. If specified, count must be greater than or equal to 1. 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