summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/advopt.txt3
-rw-r--r--doc/basicopt.txt1
-rw-r--r--doc/lib.rst7
-rw-r--r--doc/manual/generics.txt54
-rw-r--r--doc/manual/pragmas.txt8
-rw-r--r--doc/manual/type_sections.txt3
-rw-r--r--doc/tut1.rst3
-rw-r--r--doc/tut2.rst17
8 files changed, 56 insertions, 40 deletions
diff --git a/doc/advopt.txt b/doc/advopt.txt
index fb6fd719b..60fd081b8 100644
--- a/doc/advopt.txt
+++ b/doc/advopt.txt
@@ -7,7 +7,8 @@ Advanced commands:
   //rst2html                convert a reStructuredText file to HTML
   //rst2tex                 convert a reStructuredText file to TeX
   //jsondoc                 extract the documentation to a json file
-  //jsondoc2                extract documentation to a json file (uses doc2)
+  //jsondoc2                extract the documentation to a json file (uses doc2)
+  //ctags                   create a tags file
   //buildIndex              build an index for the whole documentation
   //run                     run the project (with Tiny C backend; buggy!)
   //genDepend               generate a DOT file containing the
diff --git a/doc/basicopt.txt b/doc/basicopt.txt
index 3b0271077..4db2d5af7 100644
--- a/doc/basicopt.txt
+++ b/doc/basicopt.txt
@@ -5,7 +5,6 @@
 Command:
   //compile, c                compile project with default code generator (C)
   //doc                       generate the documentation for inputfile
-  //doc2                      generate the documentation for inputfile
 
 Arguments:
   arguments are passed to the program being run (if --run option is selected)
diff --git a/doc/lib.rst b/doc/lib.rst
index 069fcc87c..6dd3f5bea 100644
--- a/doc/lib.rst
+++ b/doc/lib.rst
@@ -64,7 +64,6 @@ Core
 * `cpuinfo <cpuinfo.html>`_
   This module implements procs to determine the number of CPUs / cores.
 
-
 Collections and algorithms
 --------------------------
 
@@ -182,6 +181,12 @@ Generic Operating System Services
   This module implements asynchronous file reading and writing using
   ``asyncdispatch``.
 
+* `distros <distros.html>`_
+  This module implements the basics for OS distribution ("distro") detection and the OS's native package manager.
+  Its primary purpose is to produce output for Nimble packages, but it also contains the widely used **Distribution** enum
+  that is useful for writing platform specific code.
+
+
 Math libraries
 --------------
 
diff --git a/doc/manual/generics.txt b/doc/manual/generics.txt
index cceea33c0..1ba62bb5c 100644
--- a/doc/manual/generics.txt
+++ b/doc/manual/generics.txt
@@ -9,26 +9,26 @@ The following example shows a generic binary tree can be modelled:
 
 .. code-block:: nim
   type
-    BinaryTreeObj[T] = object    # BinaryTreeObj is a generic type with
-                                 # with generic param ``T``
-      le, ri: BinaryTree[T]      # left and right subtrees; may be nil
-      data: T                    # the data stored in a node
-    BinaryTree[T] = ref BinaryTreeObj[T] # a shorthand for notational convenience
+    BinaryTree*[T] = ref object # BinaryTree is a generic type with
+                                # generic param ``T``
+      le, ri: BinaryTree[T]     # left and right subtrees; may be nil
+      data: T                   # the data stored in a node
 
-  proc newNode[T](data: T): BinaryTree[T] = # constructor for a node
+  proc newNode*[T](data: T): BinaryTree[T] =
+    # constructor for a node
     new(result)
     result.data = data
 
-  proc add[T](root: var BinaryTree[T], n: BinaryTree[T]) =
+  proc add*[T](root: var BinaryTree[T], n: BinaryTree[T]) =
+    # insert a node into the tree
     if root == nil:
       root = n
     else:
       var it = root
       while it != nil:
-        var c = cmp(it.data, n.data) # compare the data items; uses
-                                     # the generic ``cmp`` proc that works for
-                                     # any type that has a ``==`` and ``<``
-                                     # operator
+        # compare the data items; uses the generic ``cmp`` proc
+        # that works for any type that has a ``==`` and ``<`` operator
+        var c = cmp(it.data, n.data)
         if c < 0:
           if it.le == nil:
             it.le = n
@@ -40,20 +40,28 @@ The following example shows a generic binary tree can be modelled:
             return
           it = it.ri
 
-  iterator inorder[T](root: BinaryTree[T]): T =
-    # inorder traversal of a binary tree
-    # recursive iterators are not yet implemented, so this does not work in
-    # the current compiler!
-    if root.le != nil: yield inorder(root.le)
-    yield root.data
-    if root.ri != nil: yield inorder(root.ri)
+  proc add*[T](root: var BinaryTree[T], data: T) =
+    # convenience proc:
+    add(root, newNode(data))
+
+  iterator preorder*[T](root: BinaryTree[T]): T =
+    # Preorder traversal of a binary tree.
+    # Since recursive iterators are not yet implemented,
+    # this uses an explicit stack (which is more efficient anyway):
+    var stack: seq[BinaryTree[T]] = @[root]
+    while stack.len > 0:
+      var n = stack.pop()
+      while n != nil:
+        yield n.data
+        add(stack, n.ri)  # push right subtree onto the stack
+        n = n.le          # and follow the left pointer
 
   var
-    root: BinaryTree[string]  # instantiate a BinaryTree with the type string
-  add(root, newNode("hallo")) # instantiates generic procs ``newNode`` and
-  add(root, newNode("world")) # ``add``
-  for str in inorder(root):
-    writeLine(stdout, str)
+    root: BinaryTree[string] # instantiate a BinaryTree with ``string``
+  add(root, newNode("hello")) # instantiates ``newNode`` and ``add``
+  add(root, "world")          # instantiates the second ``add`` proc
+  for str in preorder(root):
+    stdout.writeLine(str)
 
 
 Is operator
diff --git a/doc/manual/pragmas.txt b/doc/manual/pragmas.txt
index db7ce7e63..835b6909d 100644
--- a/doc/manual/pragmas.txt
+++ b/doc/manual/pragmas.txt
@@ -102,6 +102,14 @@ collector to not consider objects of this type as part of a cycle:
       left, right: Node
       data: string
 
+Or if we directly use a ref object:
+
+.. code-block:: nim
+  type
+    Node = ref object {.acyclic, final.}
+      left, right: Node
+      data: string
+
 In the example a tree structure is declared with the ``Node`` type. Note that
 the type definition is recursive and the GC has to assume that objects of
 this type may form a cyclic graph. The ``acyclic`` pragma passes the
diff --git a/doc/manual/type_sections.txt b/doc/manual/type_sections.txt
index af761c77e..12b2a11ac 100644
--- a/doc/manual/type_sections.txt
+++ b/doc/manual/type_sections.txt
@@ -5,8 +5,7 @@ Example:
 
 .. code-block:: nim
   type # example demonstrating mutually recursive types
-    Node = ref NodeObj # a traced pointer to a NodeObj
-    NodeObj = object
+    Node = ref object  # an object managed by the garbage collector (ref)
       le, ri: Node     # left and right subtrees
       sym: ref Sym     # leaves contain a reference to a Sym
 
diff --git a/doc/tut1.rst b/doc/tut1.rst
index be5cd8c11..6731efde9 100644
--- a/doc/tut1.rst
+++ b/doc/tut1.rst
@@ -1511,8 +1511,7 @@ operators perform implicit dereferencing operations for reference types:
 .. code-block:: nim
 
   type
-    Node = ref NodeObj
-    NodeObj = object
+    Node = ref object
       le, ri: Node
       data: int
   var
diff --git a/doc/tut2.rst b/doc/tut2.rst
index 0bb4c94e1..0636c4ed6 100644
--- a/doc/tut2.rst
+++ b/doc/tut2.rst
@@ -104,15 +104,14 @@ Example:
 
 .. code-block:: nim
   type
-    Node = ref NodeObj # a traced reference to a NodeObj
-    NodeObj = object
+    Node = ref object  # a reference to an object with the following field:
       le, ri: Node     # left and right subtrees
       sym: ref Sym     # leaves contain a reference to a Sym
 
     Sym = object       # a symbol
       name: string     # the symbol's name
       line: int        # the line the symbol was declared in
-      code: Node      # the symbol's abstract syntax tree
+      code: Node       # the symbol's abstract syntax tree
 
 
 Type conversions
@@ -155,8 +154,7 @@ An example:
       nkAdd,          # an addition
       nkSub,          # a subtraction
       nkIf            # an if statement
-    Node = ref NodeObj
-    NodeObj = object
+    Node = ref object
       case kind: NodeKind  # the ``kind`` field is the discriminator
       of nkInt: intVal: int
       of nkFloat: floatVal: float
@@ -482,11 +480,10 @@ containers:
 
 .. code-block:: nim
   type
-    BinaryTreeObj[T] = object # BinaryTree is a generic type with
-                              # with generic param ``T``
-      le, ri: BinaryTree[T]   # left and right subtrees; may be nil
-      data: T                 # the data stored in a node
-    BinaryTree*[T] = ref BinaryTreeObj[T] # type that is exported
+    BinaryTree*[T] = ref object # BinaryTree is a generic type with
+                                # generic param ``T``
+      le, ri: BinaryTree[T]     # left and right subtrees; may be nil
+      data: T                   # the data stored in a node
 
   proc newNode*[T](data: T): BinaryTree[T] =
     # constructor for a node
aram <vc@akkartik.com> 2020-09-07 23:35:18 -0700 committer Kartik Agaram <vc@akkartik.com> 2020-09-07 23:35:18 -0700 6757' href='/akkartik/mu/commit/apps/browse/paginated-screen.mu?h=hlt&id=571ff107a26a2bc1932ec9dc0d62365f99e385f9'>571ff107 ^
3f4aedd8 ^

9818804c ^
1ef8d4db ^







83fc84ee ^
3f4aedd8 ^



83fc84ee ^













a3f77915 ^
9818804c ^
485228ed ^
9818804c ^






a3f77915 ^
9818804c ^











485228ed ^
9818804c ^
a3f77915 ^
485228ed ^
a3f77915 ^
485228ed ^

66491081 ^
1ef8d4db ^


fc42975c ^
66491081 ^
83fc84ee ^




fc42975c ^
83fc84ee ^

bebb90a2 ^


83fc84ee ^







3f4aedd8 ^
83fc84ee ^





485228ed ^
83fc84ee ^
d9a05dfb ^




a03daa83 ^


9818804c ^


a03daa83 ^
d9a05dfb ^

8617fa2f ^
d9a05dfb ^

3f4aedd8 ^




9818804c ^
a03daa83 ^


9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^
3f4aedd8 ^






20b15942 ^




a03daa83 ^


9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^
20b15942 ^






1ef8d4db ^




a03daa83 ^


9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^
1ef8d4db ^






3f4aedd8 ^




a03daa83 ^


9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^
3f4aedd8 ^











a03daa83 ^


9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^
3f4aedd8 ^






4eedb680 ^




a03daa83 ^


9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^



9818804c ^


a03daa83 ^
4eedb680 ^







8c9b8e8f ^
66491081 ^
485228ed ^



8c9b8e8f ^
83fc84ee ^

485228ed ^
83fc84ee ^
66491081 ^

bebb90a2 ^

3f4aedd8 ^




bebb90a2 ^



















































83fc84ee ^
485228ed ^



9818804c ^
485228ed ^










3f4aedd8 ^


485228ed ^










9818804c ^
485228ed ^
485228ed ^







d9a05dfb ^
485228ed ^

d9a05dfb ^

485228ed ^

9818804c ^



d9a05dfb ^
1ef8d4db ^

d9a05dfb ^
485228ed ^

9818804c ^


485228ed ^










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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661