OILS / spec / testdata / module2 / globals.ysh View on Github | oilshell.org

36 lines, 15 significant
1
2# We can provide a shortcut:
3
4# export mutate-g1 mutateG2
5# export --funcs --procs # for convenience
6
7const __provide__ = :| mutate-g1 mutateG2 |
8
9var g1 = 'g1'
10var g2 = 'g2'
11
12var d = {g: 1}
13#pp test_ ([id(d), d])
14
15proc mutate-g1 {
16 echo "g1 = $g1"
17 setglobal g1 = 'proc mutated'
18 echo "g1 = $g1"
19
20 setglobal d = {'proc mutated': 42}
21
22 #pp test_ ([id(d), d])
23}
24
25# Should we disallow setglobal in func? Yes I think so
26func mutateG2() {
27 echo "g2 = $g2"
28 setglobal g2 = 'func mutated'
29 echo "g2 = $g2"
30}
31
32#pp frame_vars_
33
34#mutate-g1
35#call mutateG2()
36