File: LazyEnvir.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (98 lines) | stat: -rw-r--r-- 2,354 bytes parent folder | download | duplicates (4)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class:: LazyEnvir
summary:: lazy environment
categories:: JITLib>Environments, Live Coding, Collections>Unordered
related:: Classes/Maybe, Classes/Fdef, Classes/Environment, Classes/ProxySpace, Overviews/JITLib

description::
Environment with deferred evaluation and default values.

Consequently, calculations can be done with nonexisting objects which can then be assigned later.
Per default, a LazyEnvir returns instances of link::Classes/Maybe::. See also link::Classes/Fdef::.

note::While the method put is treated as transparent and implicitly creates a placeholder, all other methods, like at, collect, do, etc. pass the placeholder. In order to retrieve the object itself, use .source - in order to reduce it to a value, use: value::

code::
e = LazyEnvir.new;
e.use { ~x = ~y + ~z };
e.at(\x);
e.at(\x).source; // the source is a binary operation (addition on the placeholders)
e.use { ~y = 5; ~z = 7 };
e.at(\x).value; // the value is 12
::

InstanceMethods::

method::put
Sets the value of the reference at key.

method::at
Returns a reference to the object at key.

code::
l = LazyEnvir.push;

// default objects are created on access
~a;
~a.value; // defaults to nil

// operations on placeholders
(
~c = ~a + ~b;

~c.value; // doesn't fail, instead returns nil
)

// variables can be assigned later
(
~a = 800;
~b = { 1.0.rand };

~c.value;
)

// variables can be exchanged later
(
~b = { 1000.rand };
~c.value;
)
::

method::copy
Copies the environment into a new one, with each placeholder being copied as well.

method::localPut
Sets the value of the key directly. This method is mainly used internally.

method::proxyClass
Specify what placeholder object the environment uses by supplying a class name (link::Classes/Symbol::). The default is a link::Classes/Maybe::. Any object that responds to the methods source, source_ and clear can be a placeholder.

code::

// making a pattern space using LazyEnvir

a = LazyEnvir.new;
a.proxyClass=\PatternProxy;

a.push;

~x = Pseq([1, 2, 30], 1);
~y = Pseq([~x], inf);

z = ~y.asStream;

z.next;
z.next;
z.next;
~x = Pseq([100, 2, 300], 1);
z.next;
z.next;
z.next;

a.pop;
::

method::removeAt
Removes the placeholder from the environment and clears it.

method::makeProxy
Returns a new placeholder object. This is used internally and can be overridden to implement other lazy environments.