Tcl Library Source Code

Check-in [63c4b82f14]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added documentation for lazyset
Timelines: family | ancestors | descendants | both | add-lazyset
Files: files | file ages | folders
SHA3-256: 63c4b82f1433ba48bc604f283192f49ddf48e53d4ee379d623cbcd9860e3f6ed
User & Date: rkeene 2018-12-31 04:48:23
Context
2018-12-31
04:49
Updated to only append one name if array is not being used check-in: 3f2d995fa7 user: rkeene tags: add-lazyset
04:48
Added documentation for lazyset check-in: 63c4b82f14 user: rkeene tags: add-lazyset
03:56
Added lazyset to modules index check-in: 00eb13763b user: rkeene tags: add-lazyset
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added modules/lazyset/lazyset.man.






























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin lazyset n 1]
[copyright {2018 Roy Keene}]
[moddesc   {Lazy evaluation for variables and arrays}]
[category  Utility]
[titledesc {Lazy evaluation}]
[require Tcl 8.5]
[require lazyset [opt 1]]
[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 ../doctools2base/include/feedback.inc]
[manpage_end]