dicttool(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– dicttool β€” Dictionary Tools πŸ’–

okay bestie, so this is dicttool(3tcl), a manual page from the tcllib crew, and it's genuinely one of my faves because it's just ✨quality of life✨ for dict. Sit with me, we're gonna go through it together. 🫢


✨ NAME ✨

dicttool β€” Dictionary Tools. that's it, that's the name, short and iconic. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

package require Tcl 8.5 9

package require dicttool ?1.2?

ladd varname args

ldelete varname args

dict getnull args

dict print dict

dict is_dict value

rmerge args

so first you need Tcl 8.5 through 9 (yes, both, she's flexible), then you pull in dicttool itself, optionally at version 1.2. then all these little cuties become available. πŸ’–


🌸 DESCRIPTION 🌸

okay so the whole vibe of dicttool is that it takes the standard dict command you already know and love and goes "what if… more". it enhances dict with several brand new commands, and β€” bonus β€” it also defines a couple of "creature comfort" list commands, because we deserve comfort. πŸ›‹οΈβœ¨

here's the polite part though: every single command in here checks whether a command with the same name already exists before adding itself. so if any of these ever slip into the Tcl core, nobody gets stomped on. considerate. we love to see it. πŸ‘‘

πŸ¦‹ ladd varname args

this one adds a new instance of each element in args to varname, but only if that element isn't already present. no duplicates, no chaos. a no-drama list. ✨

πŸ¦‹ ldelete varname args

this one deletes all instances of each element in args from varname. every single one. gone. she does not do half measures. πŸ’€

πŸ¦‹ dict getnull args

works exactly like dict get, except β€” and this is the whole point β€” if the key args doesn't exist, it returns an empty list instead of throwing an error. no tears, no stack trace, just a lil empty list. 😌

πŸ¦‹ dict print dict

this produces a string representation of dict where every nested branch gets its own newline, indented by two spaces for every level. it's giving… readable. finally. 🌈

πŸ¦‹ dict is_dict value

returns true if value can be interpreted as a dict. and the important bit: it operates in such a way that it does not force an existing dict representation to shimmer into another internal rep. so it checks without disturbing the vibe. no shimmer, no drama. 🧚

πŸ¦‹ rmerge args

this returns a dict that's the product of a recursive merge of all the arguments. unlike dict merge, this one descends into all the levels of a dict. 🌊

now listen closely, this part matters: dict keys which end in : indicate a leaf β€” that means they get interpreted as a literal value, and she will not descend into them any further. okay? okay. πŸ“

set items [dict merge {
  option {color {default: green}}
} {
  option {fruit {default: mango}}
} {
  option {color {default: blue} fruit {widget: select values: {mango apple cherry grape}}}
}]
puts [dict print $items]

and that prints the following result:

option {
  color {
    default: blue
  }
  fruit {
    widget: select
    values: {mango apple cherry grape}
  }
}

look at that nesting. look at that indentation. she ate. πŸ”₯


😭 BUGS, IDEAS, FEEDBACK 😭

okay real talk bestie, this document and the package it describes will undoubtedly contain bugs and other problems. that's just how it is. so if you find one, please report it in the category dict of the Tcllib Trackers:

http://core.tcl.tk/tcllib/reportlist

and hey β€” if you've got ideas for enhancements for either the package and/or the documentation, report those too! we want them!! 🫢

when proposing code changes, please provide unified diffs, i.e. the output of diff -u. no freestyle, bestie, we need the format.

also, note further that attachments are strongly preferred over inlined patches. you can attach stuff 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 move. πŸ’…


πŸŽ€ KEYWORDS πŸŽ€

dict


πŸ‘‘ CATEGORY πŸ‘‘

Utilities


Copyright (c) 2017 Sean Woods <yoda@etoyoc.com>


and that's the whole page, bestie! this one's from tcllib, version 1.2, and it's the dicttool(3tcl) manual β€” go forth and merge recursively. no cap. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from