File: scope-assignment-tests.scad

package info (click to toggle)
openscad 2021.01-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,096 kB
  • sloc: cpp: 53,199; sh: 4,384; ansic: 4,382; python: 1,813; yacc: 853; javascript: 762; lex: 417; lisp: 163; xml: 127; makefile: 118
file content (99 lines) | stat: -rw-r--r-- 1,484 bytes parent folder | download | duplicates (5)
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
99
echo("union scope");
a = 4; 
union() { 
  a = 5; 
  echo("local a (5):", a); 
} 
echo("global a (4):", a);


echo("module scope:");
module mymodule(b=6) { 
  b = 7; 
  echo("local b (7)", b); 
} 
mymodule(); 
mymodule(8); 

echo("module children scope:");
module mymodule2(b2=6) { 
  b2 = 2; 
  children(0);
} 
mymodule2(b2=7) {
    b2 = 3;
    echo("b2 (3)", b2);
}

echo("for loop (c = 0,1,25):");
for (i=[0:2]) { 
  c = (i > 1) ? i + 23 : i; 
  echo("c", c); 
}

echo("if scope:");
if (true) {
    d = 8;
    echo("d (8)", d);
}

echo("else scope:");
if (false) {
} else {
    d = 9;
    echo("d (9)", d);
}

echo("anonymous inner scope (scope ignored):");
union() {
    e = 2;
    echo("outer e (3)", e);
    {
        e = 3;
        echo("inner e (3)", e);
    }
}

echo("anonymous scope (scope ignored):"); 
f=1; 
echo("outer f (2)", f); 
{ 
    f=2; 
    echo("inner f (2)", f); 
}

echo("anonymous scope reassign:");
{ 
    g=1; 
    echo("g (2)", g);
    g=2; 
}

echo("anonymous reassign using outer (scope ignored)", h); 
h=5; 
{ 
    h=h*2; // Not allowed
    echo("h (undef)", h); 
} 

echo("override variable in assign scope:");
assign(i=9) {
    i=10;
    echo("i (10)", i);
}

echo("group scope:");
group() {
  a=11;
  echo("local a (11)", a);
}

echo("legimate case for module parameter overwrite: (see #2628)");
function clamp(a) = a > 10 ? 10 : a < 0 ? 0: a;

module mytest(a=5){
    a=clamp(echo("parameter a(20)", a) a);
    echo("local a(10)", a);
}

mytest(20);