Skip to content

Commit 3f75e86

Browse files
committed
fixing isssues with documentation
1 parent 36c583c commit 3f75e86

9 files changed

Lines changed: 348 additions & 197 deletions

docs/Var/comparison_and_boolean.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,24 @@ This page documents all comparison and boolean operations for `var`, using a cle
4747
## Examples
4848

4949
```cpp
50-
#include "pythonic/pythonicVars.hpp"
51-
#include "pythonic/pythonicPrint.hpp"
52-
using namespace pythonic::vars;
53-
using pythonic::print::print;
50+
#include <pythonic/pythonic.hpp>
51+
using namespace py;
5452

55-
var a = 10;
53+
int main()
54+
{
55+
var a = 10;
5656
var b = 10.0;
5757
print(a == b); // true (numeric promotion)
5858
print(a != b); // false
59+
if(a) // any non-zero number is true
60+
{
61+
print("any non-zero number is true");
62+
}
63+
64+
if(!(b - 10))
65+
{
66+
print("Any var with value 0 is false");
67+
}
5968

6069
var s1 = "abc";
6170
var s2 = "abc";
@@ -84,11 +93,16 @@ print(list(1) || list()); // true
8493
std::set<var> st = { var(2), var(1) };
8594
for (auto &v : st) print(v); // 1 2
8695

96+
// Btw a lot of you might try do do this! And you will get an error! So be careful who you compare
97+
8798
try {
8899
print(dict({{"a",1}}) > list(1));
89100
} catch (const pythonic::PythonicTypeError &e) {
90101
print("comparison error:", e.what());
91102
}
103+
return 0;
104+
}
105+
92106
```
93107
94108
---

docs/Var/construction_and_lifetime.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This page documents all ways to construct and manage the lifetime of a `var` obj
2020
| `var(const char*)` | String | `var s("hello"); // "hello"` |
2121
| `var(const std::string&)` | String | `var s(std::string("hi")); // "hi"` |
2222
| `var(List/Set/Dict/...)` | Container types | `var vlist(list(1,2,3));` |
23-
| `var(Graph)` | Graph (VarGraph wrapper) | `var vg(Graph(5));` |
23+
| `graph(n)` | Graph (VarGraph wrapper) | `var vg = graph(5);` |
2424

2525
---
2626

@@ -103,8 +103,9 @@ OrderedDict od = { {"k1", var(1)}, {"k2", var(2)} };
103103
var vod(od);
104104

105105
// --- Graph Constructor ---
106-
Graph g(5); g.add_edge(0, 1);
107-
var vg(g);
106+
var vg = graph(5); // recommended
107+
vg.add_edge(0, 1);
108+
vg.save_graph("mygraph.txt"); // save the graph to a file
108109

109110
// --- Converter Helpers ---
110111
var vstr = "123";
@@ -128,7 +129,8 @@ var fodset = ordered_set(3, 1, 2);
128129
var fdict = dict({{"a", 1}, {"b", 2}});
129130
var fodict = ordered_dict({{"k1", 1}, {"k2", 2}});
130131
var fgraph = graph(5);
131-
auto loaded = load_graph("/path/to/graph.file");
132+
var loaded = load_graph("mygraph.txt"); // load the graph from the file
133+
//auto loaded = load_graph("/path/to/graph.file");
132134

133135

134136
// --- input ---
@@ -157,4 +159,4 @@ print(copy, moved);
157159
158160
## Next check
159161
160-
- [Type Introspection & Conversion](type_introspection_and_conversion.md)
162+
- [Type Introspection & Conversion](type_introspection_and_conversion.md)

docs/Var/container_and_sequence_operations.md

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,56 @@ This page documents all user-facing container and sequence APIs for `var`, in a
3939
## Examples
4040

4141
```cpp
42-
#include "pythonic/pythonic.hpp"
42+
#include <pythonic/pythonic.hpp>
4343
using namespace py;
4444

45-
var vlist = list(1, 2, 3);
46-
vlist.append(4); // [1,2,3,4]
47-
vlist.extend(list(5,6)); // [1,2,3,4,5,6]
48-
vlist.remove(2); // [1,3,4,5,6]
49-
print(vlist.len()); // 5
50-
print(vlist.front()); // 1
51-
print(vlist.back()); // 6
52-
print(vlist.at(2)); // 4
53-
print(vlist[1]); // 3
54-
print(vlist.slice(1,4)); // [3,4,5]
55-
print(vlist(1,4)); // [3,4,5]
56-
print(vlist.empty()); // false
57-
vlist.clear();
58-
print(vlist.empty()); // true
59-
60-
var vset = set(1,2,3);
61-
vset.add(4);
62-
vset.update(set(5,6));
63-
print(vset.contains(3)); // true
64-
print(vset.has(5)); // true
65-
vset.remove(1);
66-
67-
var vdict = dict({{"a", 1}, {"b", 2}});
68-
print(vdict["a"]); // 1
69-
print(vdict.keys()); // ["a", "b"]
70-
print(vdict.values()); // [1,2]
71-
print(vdict.items()); // [("a",1), ("b",2)]
72-
73-
// Iteration
74-
for (auto it = vdict.begin(); it != vdict.end(); ++it) {
75-
// ...
45+
int main()
46+
{
47+
var vlist = list(1, 2, 3);
48+
vlist.append(4); // [1,2,3,4]
49+
vlist.extend(list(5,6)); // [1,2,3,4,5,6]
50+
vlist.remove(2); // [1,3,4,5,6]
51+
print(vlist.len()); // 5
52+
print(vlist.front()); // 1
53+
print(vlist.back()); // 6
54+
print(vlist.at(2)); // 4
55+
print(vlist[1]); // 3
56+
print(vlist.slice(1,4)); // [3,4,5]
57+
print(vlist(1,4)); // [3,4,5]
58+
print(vlist.empty()); // false
59+
vlist.clear();
60+
print(vlist.empty()); // true
61+
62+
var vset = set(1,2,3);
63+
vset.add(4);
64+
vset.update(set(5,6));
65+
print(vset.contains(3)); // true
66+
print(vset.has(5)); // true
67+
vset.remove(1);
68+
69+
var vdict = dict({{"a", 1}, {"b", 2}});
70+
print(vdict["a"]); // 1
71+
print(vdict.keys()); // ["a", "b"]
72+
print(vdict.values()); // [1,2]
73+
print(vdict.items()); // [("a",1), ("b",2)]
74+
for (auto it = vdict.get<Dict>().begin(); it != vdict.get<Dict>().end(); ++it)
75+
{
76+
print("key: ", it->first); // key (std::string)
77+
print("value: ", it->second); // value (var)
78+
}
79+
for (auto [key,value] : vdict.get<Dict>())
80+
{
81+
print("key: ", key); // key (std::string)
82+
print("value: ", value); // value (var)
83+
}
84+
for (auto it = vdict.begin(); it != vdict.end(); ++it)
85+
{
86+
print(1);
87+
// but you can't use it->first and it->second here as the vdict is not a std::map. also you can not do auto[key,value] like iteration directly on vdict, you have to use vdict.get<Dict>() to get the underlying std::map
88+
}
89+
return 0;
7690
}
91+
7792
```
7893

7994
---

0 commit comments

Comments
 (0)