1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
[vset VERSION 1]
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin lazyset n [vset VERSION]]
[copyright {2018 Roy Keene}]
[moddesc {Lazy evaluation for variables and arrays}]
[category Utility]
[titledesc {Lazy evaluation}]
[require Tcl 8.5]
[require lazyset [opt [vset VERSION]]]
[description]
[para]
The [package lazyset] package provides a mechanism for deferring execution
of code until a specific variable or any index of an array is referenced.
[section {COMMANDS}]
[list_begin definitions]
[call [cmd ::lazyset::variable] [opt [arg {-array boolean}]] [opt [arg {-appendArgs boolean}]] [arg variableName] [arg commandPrefix]]
Arrange for the code specified as [arg commandPrefix] to be executed when
the variable whose name is specified by [arg variableName] is read for
the first time.
If the optional argument [arg {-array boolean}] is specified as true,
then the variable specified as [arg variableName] is treated as an
array and attempting to read any index of the array causes that
index to be set by the [arg commandPrefix] as they are read.
If the optional argument [arg {-appendArgs boolean}] is specified as
false, then the variable name and subnames are not appended to the
[arg commandPrefix] before it is evaluated. If the argument
[arg {-appendArgs boolean}] is not specified or is specified as true
then 1 or 2 additional arguments are appended to the [arg commandPrefix].
If [arg {-array boolean}] 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 [arg commandPrefix] code is run in the same scope as the variable
is read.
[list_end]
[section EXAMPLES]
[example {
::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
}]
[example {
::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/)
}]
[example {
::lazyset::variable -appendArgs false simple {
return -level 0 42
}
puts $simple
}]
[section AUTHORS]
Roy Keene
[vset CATEGORY utility]
[include ../common-text/feedback.inc]
[manpage_end]
|