-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables_as_storage.txt
134 lines (106 loc) · 3.24 KB
/
variables_as_storage.txt
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Variables as text storage
=========================
[[Parent]]: variables.txt
This section introduces the basic use of variables in Remark.
Here we view variables as a way to store and retrieve text.
Defining variables
------------------
[[Example]]:
[[set Gallery.thumbnail_max_width: 500]]
[[Gallery.thumbnail_max_width]]
[[Example]]:
[[set some_file_list]]:
filename.txt
another.txt
[[some_file_list]]
[[Example]]:
[[set_many]]:
Gallery.thumbnail_max_width 300
Gallery.thumbnail_max_height 400
[[Gallery.thumbnail_max_width]]
[[Gallery.thumbnail_max_height]]
[[Example]]:
[[set_many Gallery]]:
thumbnail_max_width 200
thumbnail_max_height 100
[[Gallery.thumbnail_max_width]]
[[Gallery.thumbnail_max_height]]
Note that with `set_many` it is not possible to assign multi-line parameters.
Appending to a variable
-----------------------
[[Example]]:
[[set some_file_list]]:
filename.txt
another.txt
[[add some_file_list]]:
third_file.txt
[[some_file_list]]
### Alternative
[[Example]]:
[[set some_file_list]]:
filename.txt
another.txt
[[+set some_file_list]]:
[[some_file_list]]
third_file.txt
[[some_file_list]]
However,
[[Verbatim]]:
[[set some_file_list]]:
filename.txt
another.txt
[[set some_file_list]]:
[[some_file_list]]
third_file.txt
[[some_file_list]]
sends Remark into a never-ending loop (Python cuts the recursion).
Variable scopes
---------------
Each variable lives in some scope which defines its visibility and
life-time. Each macro-invocation creates a child-scope into the
current scope. Variables defined inside the macro-invocation are
placed into this scope. When a macro finishes, its scope is closed
and all the local variables in the scope are destroyed. When no
macro invocations are active, the only active scope is the _global
scope_. Child scopes can refer to variables in the parent scopes,
but not vice versa. When a variable that does not exist in the
current scope is set, a new local variable is created.
[[Example]]:
[[set word: world]]
[[set my_macro]]:
[[set word: jello]]
Hello [[word]]!
[[my_macro]]
word = [[word]]
That is, the variable `word` inside `set my_macro` is introduced as a
local variable and hence does not affect the variable `word` at the
outer scope.
### Retrieving a variable in an outer scope
The `get` command will look at outer scopes if a variable is not
found at the local scope. However, when there is _both_ a local variable
and a variable of the same name in an outer scope, the latter can be
retrieved with the `outer` command.
[[Example]]:
[[set word: world]]
[[set my_macro]]:
[[set word: jello]]
Hello [[outer word]]!
[[my_macro]]
word = [[word]]
### Setting a variable in an outer scope
The `set` command always creates a local variable. You
can use the `set_outer` command to set an existing variable
at an outer scope. In case no such variable is found, a
new variable is created at the global scope.
[[Example]]:
[[set word: world]]
[[set my_macro]]:
[[set word: cello]]
[[set_outer word: jello]]
Hello [[word]]!
Hello [[outer word]]!
[[my_macro]]
word = [[word]]
### Appending a variable in an outer scope.
The `add_outer` command works similarly to `set_outer`,
but instead of assigning, it appends text.