lazyset - Lazy evaluation
Contents
Bugs, Ideas, Feedback
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please
report such in the category utility of the TcllibTrackers [http://core.tcl.tk/tcllib/reportlist].
Please also report any ideas for enhancements you may have for either package and/or documentation.
When proposing code changes, please provide unifieddiffs, 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.
Category
Utility
Commands
::lazyset::variable ?-arrayboolean? ?-appendArgsboolean? variableNamecommandPrefix
Arrange for the code specified as commandPrefix to be executed when the variable whose name is
specified by variableName is read for the first time. If the optional argument -arrayboolean is
specified as true, then the variable specified as variableName is treated as an array and
attempting to read any index of the array causes that index to be set by the commandPrefix as they
are read. If the optional argument -appendArgsboolean is specified as false, then the variable
name and subnames are not appended to the commandPrefix before it is evaluated. If the argument
-appendArgsboolean is not specified or is specified as true then 1 or 2 additional arguments are
appended to the commandPrefix. If -arrayboolean is 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 variable. The commandPrefix code is run in the same scope as the variable
is read.
Copyright
Copyright (c) 2018 Roy Keene
tcllib 1.1 lazyset(3tcl)
Description
The lazyset package provides a mechanism for deferring execution of code until a specific variable or any
index of an array is referenced.
Examples
::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
Name
lazyset - Lazy evaluation
Synopsis
package require Tcl8.59
package require lazyset?1.1?::lazyset::variable ?-arrayboolean? ?-appendArgsboolean? variableNamecommandPrefix
________________________________________________________________________________________________________________
