aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc
diff options
context:
space:
mode:
authorCFiggers <55862180+CFiggers@users.noreply.github.com>2022-10-02 15:24:22 -0700
committerGitHub <noreply@github.com>2022-10-02 15:24:22 -0700
commit66769713ac84e4c5eebfa32807c18d1b803a912f (patch)
treeffeb19c1214891a77fdfda6ee48051719da69b92 /doc
parentUse `splice` (or `;`) rather than `apply` (diff)
Minor edits to `docs/data.mdz`
- Replaced references to "map" (Clojure style) with either "struct" or "table" (Janet style) - Added link to https://clojure.org/ on "Clojure" in first sentence - Updated link to `clojure.data` to point to the public API documentation rather than the GitHub source, with source also linked in parentheses afterwards.
Diffstat (limited to 'doc')
-rw-r--r--doc/data.mdz14
1 files changed, 7 insertions, 7 deletions
diff --git a/doc/data.mdz b/doc/data.mdz
index 02fe04d..5dceae1 100644
--- a/doc/data.mdz
+++ b/doc/data.mdz
@@ -4,7 +4,7 @@
:template "mdzdoc/main.html"
:order 0}
---
-Clojure contains a very useful core library called @link[https://github.com/clojure/clojure/blob/51c6d7a70912a8f65e81a8e11ae6f56c94920725/src/clj/clojure/data.clj]{clojure.data}. It contains one "exported" function: @code`clojure.data/diff`. This addition to spork, @code`data.janet`, should exactly replicate the behavior of @code`clojure.data/diff` using Janet tables, structs, arrays, and tuples in place of their Clojure equivalents.
+@link[https://clojure.org/]{Clojure} contains a very useful core library (or "namespace" in Clojure parlance) called @link[https://clojure.github.io/clojure/clojure.data-api.html]{clojure.data} (@link[https://github.com/clojure/clojure/blob/51c6d7a70912a8f65e81a8e11ae6f56c94920725/src/clj/clojure/data.clj]{source}). It contains one "exported" function: @code`clojure.data/diff`. This addition to spork, @code`data.janet`, should exactly replicate the behavior of @code`clojure.data/diff` using Janet tables, structs, arrays, and tuples in place of their Clojure equivalents.
## Function
@@ -12,7 +12,7 @@ The @code`diff` function recursively compares the structure and contents of two
@code`@[things-only-in-a things-only-in-b things-in-both]`
-In the case of nested maps, the comparison is recursive and the data structures are neatly partitioned into the same @code`@[things-only-in-a things-only-in-b things-in-both]` structure, but arbitrary levels deep in the two original associative data structures.
+In the case of nested associative data structures (i.e., tables and structs), the comparison is recursive and the data structures are neatly partitioned into the same @code`@[things-only-in-a things-only-in-b things-in-both]` structure, but arbitrary levels deep in the two original associative data structures.
This function makes comparing two structs or tables for changes trivial. (An example use case: compare the decoded JSON returned from a REST API call made seconds ago against the version of that same decoded JSON from that same API that was returned from the same call made an hour ago and stored locally in a database for comparison an hour later.)
@@ -29,9 +29,9 @@ repl:2:> (d/diff {:a 1 :b 2 :c {:d 3 :e 4}} {:a 4 :b 2 :c {:d 3 :e 5 :f 6}})
The return is @code`@[@{:a 1 :c @{:e 4}} @{:a 4 :c @{:e 5 :f 6}} @{:b 2 :c @{:d 3}}]` because:
@ul{
- @li{the value for @code`:a` appears in both and is different in each one (so @code`:a` is a key in both the first and second map, with each value set as seen in the first and second original maps)}
- @li{the value for @code`:b` appears in both and is the same in each (so @code`:b` is a key only in the third map, containing the shared value in both original maps)}
- @li{the nested value of @code`:d` appears in both and is the same in each (so @code`:c` is a key in the third map, containing the value of @code`:d` that is shared in both original maps)}
- @li{the nested value of @code`:e` appears in both and is different in each one (so @code`:c` is a key in both the first and second map, containing the value @code`:e` with with each value set as seen in the first and second original maps), and}
- @li{the key/value pair @code`:f` 6 only appears in the latter map (so only the second map contains @code`:f` and its value).}
+ @li{the value for @code`:a` appears in both and is different in each one (so @code`:a` is a key in both the first and second returned table, with each value set as seen in the first and second original structs)}
+ @li{the value for @code`:b` appears in both and is the same in each (so @code`:b` is a key only in the third returned table, containing the shared value in both original strucs)}
+ @li{the nested value of @code`:d` appears in both and is the same in each (so @code`:c` is a key in the third returned table, containing the value of @code`:d` that is shared in both original structs)}
+ @li{the nested value of @code`:e` appears in both and is different in each one (so @code`:c` is a key in both the first and second returned table, containing the value @code`:e` with with each value set as seen in the first and second original structs), and}
+ @li{the key/value pair @code`:f` 6 only appears in the latter original struct (so only the second returned table contains @code`:f` and its value).}
}