1lazyset(n)         Lazy evaluation for variables and arrays         lazyset(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       lazyset - Lazy evaluation
9

SYNOPSIS

11       package require Tcl  8.5
12
13       package require lazyset  ?1?
14
15       ::lazyset::variable ?-array boolean? ?-appendArgs boolean? variableName
16       commandPrefix
17
18______________________________________________________________________________
19

DESCRIPTION

21       The lazyset package provides a mechanism  for  deferring  execution  of
22       code until a specific variable or any index of an array is referenced.
23

COMMANDS

25       ::lazyset::variable ?-array boolean? ?-appendArgs boolean? variableName
26       commandPrefix
27              Arrange for the code specified as commandPrefix to  be  executed
28              when  the  variable  whose  name is specified by variableName is
29              read for the first time.  If the optional argument -array  bool‐
30              ean  is  specified as true, then the variable specified as vari‐
31              ableName is treated as an array and attempting to read any index
32              of the array causes that index to be set by the commandPrefix as
33              they are read.  If the optional argument -appendArgs boolean  is
34              specified  as false, then the variable name and subnames are not
35              appended to the commandPrefix before it is  evaluated.   If  the
36              argument -appendArgs boolean is not specified or is specified as
37              true then 1 or 2 additional arguments are appended to  the  com‐
38              mandPrefix.   If -array boolean is specified as true, then 2 ar‐
39              guments are appended corresponding to the name of  the  variable
40              and  the  index, otherwise 1 argument is appended containing the
41              name of variable.  The commandPrefix code is  run  in  the  same
42              scope as the variable is read.
43

EXAMPLES

45                ::lazyset::variable page {apply {{name} {
46                   package require http
47                   set token [http::geturl http://www.tcl.tk/]
48                   set data [http::data $token]
49                   return $data
50                }}}
51
52                puts $page
53
54
55
56                ::lazyset::variable -array true page {apply {{name index} {
57                   package require http
58                   set token [http::geturl $index]
59                   set data [http::data $token]
60                   return $data
61                }}}
62
63                puts $page(http://www.tcl.tk/)
64
65
66
67                ::lazyset::variable -appendArgs false simple {
68                   return -level 0 42
69                }
70
71                puts $simple
72
73

AUTHORS

75       Roy Keene
76

BUGS, IDEAS, FEEDBACK

78       This  document,  and the package it describes, will undoubtedly contain
79       bugs and other problems.  Please report such in the category utility of
80       the  Tcllib  Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please
81       also report any ideas for enhancements you may have for either  package
82       and/or documentation.
83
84       When proposing code changes, please provide unified diffs, i.e the out‐
85       put of diff -u.
86
87       Note further that  attachments  are  strongly  preferred  over  inlined
88       patches.  Attachments  can  be  made  by  going to the Edit form of the
89       ticket immediately after its creation, and  then  using  the  left-most
90       button in the secondary navigation bar.
91

CATEGORY

93       Utility
94
96       Copyright (c) 2018 Roy Keene
97
98
99
100
101tcllib                                 1                            lazyset(n)
Impressum