Skip to content

Commit 291f80a

Browse files
authored
Update README.md
Put cycle detection inside Risks section
1 parent 16ebe17 commit 291f80a

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

README.md

+29-29
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,6 @@ expressing branches; Nodely allows for conditional dependencies that
6060
defer evaluation until run time checks have determined it is necessary
6161
to evaluate a dependency.
6262

63-
### Cycle Detection
64-
65-
Nodely provides a handy function that throws an error when a cycle has been detected in your _environment_. To use this function, simply execute the following code:
66-
67-
```clj
68-
(comment
69-
(require '[nodely.api.v0 :as nodely])
70-
(nodely/checked-env
71-
{:a (nodely/>value 1)
72-
:b (nodely/>leaf (even? ?a))})
73-
) ;; When no cycle is detected, returns env {:a #:nodely.data{:type :value, :value 1}...}
74-
```
75-
76-
>Avoid using the `checked-env` function at runtime, as its calculations can be costly. It is recommended to perform this verification only during development, using the REPL.
77-
78-
It's important to be aware that this function may sometimes produce false positives when dealing with graphs that contain mutually exclusive conditions. Here's an example where the function might produce a false positive:
79-
80-
```clj
81-
(comment
82-
(require '[nodely.api.v0 :as nodely])
83-
(nodely/checked-env
84-
{:f (>if (>leaf ?c) :it-was-even! (>leaf ?e))
85-
:e (>if (>leaf ?c) (>leaf ?f) :it-was-odd!)
86-
:c (>leaf (even? (rand-int 2)))})
87-
) ;; throws "Checked-env found cycles at compile time"
88-
```
89-
90-
Keep in mind these limitations and double-check the results if your graph contains such scenarios.
91-
9263
## Definitions
9364

9465
### Nodes
@@ -358,6 +329,35 @@ core.async workers deadlock, waiting on each other to complete.
358329
If you see evaluation hanging, start investigating for loops in your
359330
environment.
360331

332+
### Cycle Detection
333+
334+
Nodely provides a handy function that throws an error when a cycle has been detected in your _environment_. To use this function, simply execute the following code:
335+
336+
```clj
337+
(comment
338+
(require '[nodely.api.v0 :as nodely])
339+
(nodely/checked-env
340+
{:a (nodely/>value 1)
341+
:b (nodely/>leaf (even? ?a))})
342+
) ;; When no cycle is detected, returns env {:a #:nodely.data{:type :value, :value 1}...}
343+
```
344+
345+
>Avoid using the `checked-env` function at runtime, as its calculations can be costly. It is recommended to perform this verification only during development, using the REPL.
346+
347+
It's important to be aware that this function may sometimes produce false positives when dealing with graphs that contain mutually exclusive conditions. Here's an example where the function might produce a false positive:
348+
349+
```clj
350+
(comment
351+
(require '[nodely.api.v0 :as nodely])
352+
(nodely/checked-env
353+
{:f (>if (>leaf ?c) :it-was-even! (>leaf ?e))
354+
:e (>if (>leaf ?c) (>leaf ?f) :it-was-odd!)
355+
:c (>leaf (even? (rand-int 2)))})
356+
) ;; throws "Checked-env found cycles at compile time"
357+
```
358+
359+
Keep in mind these limitations and double-check the results if your graph contains such scenarios.
360+
361361
## Related Work
362362

363363
From our knowledge there are some libraries with similar functionality, but none of them do exactly what nodely proposes

0 commit comments

Comments
 (0)