summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorHitesh Jasani <hitesh@grokken.com>2014-01-16 14:42:12 -0500
committerHitesh Jasani <hitesh@grokken.com>2014-01-16 14:42:12 -0500
commit74af6351b2b1888cc1437e158cf29851f8e6465e (patch)
tree80c0ad4948b3ae4d5292e99240ff85858a18e69d
parent1280c56f386111b542c8f0effdd3e5cbc5e84622 (diff)
downloadNim-74af6351b2b1888cc1437e158cf29851f8e6465e.tar.gz
Add docs for constraining and qualifying imports.
-rw-r--r--doc/tut1.txt35
1 files changed, 35 insertions, 0 deletions
diff --git a/doc/tut1.txt b/doc/tut1.txt
index 2070c69d6..52d46d9bd 100644
--- a/doc/tut1.txt
+++ b/doc/tut1.txt
@@ -1582,6 +1582,17 @@ rules apply:
   write(stdout, x(3))   # ambiguous: which `x` is to call?
 
 
+Excluding symbols
+-----------------
+
+The normal ``import`` statement will bring in all exported symbols.
+These can be limited by naming symbols which should be excluded with
+the ``except`` qualifier.
+
+.. code-block:: nimrod
+  import mymodule except y
+
+
 From statement
 --------------
 
@@ -1592,6 +1603,30 @@ exported symbols. An alternative that only imports listed symbols is the
 .. code-block:: nimrod
   from mymodule import x, y, z
 
+The ``from`` statement can also force namespace qualification on
+symbols, thereby making symbols available, but needing to be qualified
+to be used.
+
+.. code-block:: nimrod
+  from mymodule import x, y, z
+
+  x()           # use x without any qualification
+
+.. code-block:: nimrod
+  from mymodule import nil
+
+  mymodule.x()  # must qualify x with the module name as prefix
+
+  x()           # using x here without qualification is a compile error
+
+Since module names are generally long to be descriptive, you can also
+define a shorter alias to use when qualifying symbols.
+
+.. code-block:: nimrod
+  from mymodule as m import nil
+
+  m.x()         # m is aliasing mymodule
+
 
 Include statement
 -----------------
1e8ff6 ^
35fb38629 ^


fd31e8ff6 ^
35fb38629 ^








































fd31e8ff6 ^
35fb38629 ^









fd31e8ff6 ^
35fb38629 ^











fd31e8ff6 ^
35fb38629 ^







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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182





















































                                                                              

                     

                   



                   














                                                        


                       
                                                                   





                                                  
                                                                              














                                                               
                                                    


                         
                                             








































                                                                                
                                                                                                 









                                                                
                                                 











                                                                      
                                                                                           







                                                             
009-12-07 01:23:19 +0100

version 0.8.5: added Nimrod version of the compiler' href='/ahoang/Nim/commit/rod/semgnrc.nim?h=devel&id=e254741541b0389dfb0b675116c76a6a144b90b7'>e25474154 ^

51e01879b ^


e25474154 ^


f46870fe1 ^
5008b4446 ^
f46870fe1 ^

e25474154 ^

5008b4446 ^
e25474154 ^
5008b4446 ^


e25474154 ^


5008b4446 ^

e25474154 ^
5008b4446 ^

e25474154 ^


5008b4446 ^





51e01879b ^
e25474154 ^

5008b4446 ^
51e01879b ^
e25474154 ^
f46870fe1 ^
51e01879b ^
e25474154 ^

5008b4446 ^
51e01879b ^
e25474154 ^


51e01879b ^
f46870fe1 ^
94f425681 ^
e25474154 ^
94f425681 ^
51e01879b ^


e25474154 ^

94f425681 ^
e25474154 ^
51e01879b ^
e9d6f5a64 ^

51e01879b ^
e25474154 ^



e9d6f5a64 ^

51e01879b ^
e25474154 ^


51e01879b ^
5008b4446 ^
94f425681 ^
e25474154 ^
94f425681 ^
5008b4446 ^
51e01879b ^

7fcbdc6d4 ^
e25474154 ^
94f425681 ^
e25474154 ^


94f425681 ^
51e01879b ^


94f425681 ^
e9d6f5a64 ^
e25474154 ^

94f425681 ^
e25474154 ^

94f425681 ^
51e01879b ^

d10973adb ^
94f425681 ^
e9d6f5a64 ^
e25474154 ^

94f425681 ^
e25474154 ^


e9d6f5a64 ^
51e01879b ^

e25474154 ^

94f425681 ^
e25474154 ^


e9d6f5a64 ^
e25474154 ^
94f425681 ^
e25474154 ^


5b28d0820 ^
e25474154 ^
51e01879b ^

e25474154 ^

51e01879b ^
e25474154 ^

5b28d0820 ^
51e01879b ^
e25474154 ^
94f425681 ^
e25474154 ^



d10973adb ^
e25474154 ^



5b28d0820 ^
51e01879b ^
e25474154 ^
94f425681 ^
e25474154 ^

94f425681 ^
51e01879b ^


e424e13bd ^
e9d6f5a64 ^
e25474154 ^
560a3bad2 ^
c51763915 ^
560a3bad2 ^
0e22a5109 ^
e25474154 ^
51e01879b ^

5b28d0820 ^

e9d6f5a64 ^
51e01879b ^

1f6725e59 ^



e25474154 ^


51e01879b ^
d10973adb ^
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267