lazyset(3tcl)

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

πŸ’– 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 as commandPrefix gets executed when the variable named variableName is read for the first time. 🫢

now for the options, because details matter:

  • if the optional argument -array boolean is specified as true, then the variable you passed as variableName is treated as an array, and attempting to read any index of that array causes that index to be set by the commandPrefix as the indices are read. lazy per-index, obsessed. ✨
  • if the optional argument -appendArgs boolean is specified as false, then the variable name and subnames are not appended to the commandPrefix before it is evaluated. πŸ’€
  • if -appendArgs boolean is not specified at all, or is specified as true, then 1 or 2 additional arguments get appended to the commandPrefix. which one? okay so:
    • if -array boolean was 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.

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 (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