lazyset(3tcl)
π lazyset β Lazy evaluation π
okay bestie, welcome to lazyset, a lil Tcllib package that lives in the lazyset(3tcl) manual and does lazy evaluation for variables and arrays. it's giving "don't do the work until somebody actually asks" energy and honestly? iconic.
β¨ NAME β¨
lazyset β lazy evaluation, but make it a personality trait π¦
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require lazyset ?1.1?
::lazyset::variable ?-array boolean? ?-appendArgs boolean? variableName
commandPrefix
like yes, that's the whole vibe up top. lazyset is the package name, and it wants Tcl 8.5 and up (well, 8.5 9, exactly like it says, no notes π
).
π DESCRIPTION π
so the lazyset package gives you a mechanism for deferring execution of code until a specific variable β or any index of an array β is actually referenced. that's it. that's the whole plot. nothing runs until you look at it. main character energy fr fr π
π COMMANDS π
::lazyset::variable ?-array boolean? ?-appendArgs boolean? variableName commandPrefixβ this is the one command, and here's the tea: you set it up so that the code you hand over ascommandPrefixgets executed when the variable namedvariableNameis read for the first time. π«Ά
now for the options, because details matter:
- if the optional argument
-array booleanis specified as true, then the variable you passed asvariableNameis treated as an array, and attempting to read any index of that array causes that index to be set by thecommandPrefixas the indices are read. lazy per-index, obsessed. β¨ - if the optional argument
-appendArgs booleanis specified as false, then the variable name and subnames are not appended to thecommandPrefixbefore it is evaluated. π - if
-appendArgs booleanis not specified at all, or is specified as true, then 1 or 2 additional arguments get appended to thecommandPrefix. which one? okay so:- if
-array booleanwas specified as true, then 2 arguments are appended β corresponding to the name of the variable and the index. - otherwise 1 argument is appended β containing the name of the variable.
- if
and the commandPrefix code runs in the same scope as the variable is read. yes, same scope. no cap.
π EXAMPLES π
okay these are the examples and they're literally the best part, look:
::lazyset::variable page {apply {{name} {
package require http
set token [http::geturl http://www.tcl.tk/]
set data [http::data $token]
return $data
}}}
puts $page
see how $page doesn't fetch anything until you actually puts it? the fetch happens on read. chef's kiss π§
and the array version, where the index becomes the URL:
::lazyset::variable -array true page {apply {{name index} {
package require http
set token [http::geturl $index]
set data [http::data $token]
return $data
}}}
puts $page(http://www.tcl.tk/)
and the "don't append anything, I'll handle it myself" version:
::lazyset::variable -appendArgs false simple {
return -level 0 42
}
puts $simple
-level 0 in there, 42 in there, all of it verbatim, exactly as written. π
π AUTHORS π
Roy Keene β the author, the moment, the legend. π
π¦ BUGS, IDEAS, FEEDBACK π¦
okay so real talk, this document and the package it describes will undoubtedly contain bugs and other problems. that's just how it is, no drama.
- please report such in the category utility of the Tcllib Trackers:
http://core.tcl.tk/tcllib/reportlist - please also report any ideas for enhancements you may have for either the package and/or the documentation.
when proposing code changes, please provide unified diffs, i.e. the output of diff -u.
also note: attachments are strongly preferred over inlined patches. you can make an attachment 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. iykyk π
β CATEGORY β
Utility
π COPYRIGHT π
Copyright (c) 2018 Roy Keene
that's the whole page, bestie β and yes, the footer says it's from tcllib 1.1, dated to match lazyset(3tcl), so you know exactly which version of the manual you just read. go be lazy, it's what the package wants. β¨π
π
π¦ 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
- Copyright (c) 2018 Roy Keene
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms