lazyset(n)

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

πŸ’… lazyset(n) β€” Lazy evaluation for variables and arrays

okay bestie, welcome to lazyset(n), the manual page for the lazyset package. it's giving "do it later but make it fashion" and honestly? iconic. ✨


✨ NAME ✨

lazyset β€” Lazy evaluation πŸ¦‹


🌸 SYNOPSIS 🌸

package require Tcl 8.5 9

package require lazyset ?1.1?

::lazyset::variable  ?-array boolean? ?-appendArgs boolean? variableName
commandPrefix

πŸ’– DESCRIPTION πŸ’–

so the lazyset package hands you a whole mechanism for deferring execution of code until a specific variable β€” or literally any index of an array β€” gets referenced. like, the code just chills there. waiting. main character energy but off-screen until you call for it. πŸŽ€


πŸ‘‘ COMMANDS πŸ‘‘

  • ::lazyset::variable ?-array boolean? ?-appendArgs boolean? variableName commandPrefix β€” this is the one and only, the moment, the whole vibe. it arranges for the code you pass as commandPrefix to get executed the first time the variable named by variableName is read. 🫢

now let's break down the options, because bestie, the details matter:

  • if the optional argument -array boolean is given as true, then the thing you named in 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 indexes are read. one by one, as they're asked for. slay. ✨
  • if the optional argument -appendArgs boolean is given as false, then the variable name and subnames are not appended to the commandPrefix before it gets evaluated. no extras, no add-ons, periodt.
  • if -appendArgs boolean is not specified at all, or it's specified as true, then 1 or 2 additional arguments get appended to the commandPrefix.
    • when -array boolean is true: 2 arguments get appended, matching the name of the variable and the index.
    • otherwise: 1 argument gets appended, containing the name of the variable.

and the tea β˜• β€” the commandPrefix code runs in the same scope as the variable is read. same scope, no cap.


🧚 EXAMPLES 🧚

here's the good stuff, copy-paste ready:

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

::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/)

::lazyset::variable -appendArgs false simple {
   return -level 0 42
}

puts $simple

see how $page just... doesn't do anything until you puts it? yeah. that's the whole point. ate. πŸ’…


🌈 AUTHORS 🌈

Roy Keene πŸ’œ


😭 BUGS, IDEAS, FEEDBACK 😭

ngl, this document, and the package it describes, will undoubtedly contain bugs and other problems. it's not a vibe, it's just reality. so please report such things in the category utility 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 want all of it. 🫢

when proposing code changes, please provide unified diffs, i.e. the output of diff -u.

also note β€” and this is important bestie β€” 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. iykyk. πŸŽ€


⭐ CATEGORY ⭐

Utility


Copyright (c) 2018 Roy Keene


and that's the whole page, bestie!! this one came to you from tcllib, version 1.1, and the page itself is dated lazyset(n). go forth and defer some code. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from