|(require spipe)||package: spipe|
The H~> form implements hash-based pipeline programming. H~> functionally threads state (a hash-table) through provided transformations. Each transformation specifies which elements to access and update in the hash table.
The grammar of transformtion follows, where non-italicized identifiers are recognized symbolically.
||||(callee read-writes ...+)|
||||(callee (reads ...) (writes ...))|
||||(callee (reads ...))|
The first transformation form callee-id is always transformed into (callee).
(callee) applies the form with the entire state as its argument, and ignoring all return values.
(callee *) is a special form that is similar to (callee) but it replaces the state with callee’s return value.
(callee read-writes ...+) simultaneously specifies variables to read from and write to. The reads are given as arguments to callee in the order they are specified. The writes are assigned to the returned values in the order they are specified.
(callee (reads ...)) for when you intend to not write to any entry.
> (H~> (hash 'hello "to you " 'world 2) (number->string world) (string-append (hello world) (hw)))
'#hash((hw . "to you 2") (hello . "to you ") (world . "2"))
Note that the above adds the symbol 'hw to the hash-table. If a write location does not exist, it is created. Entries in the hash table can not be deleted inside H~> without using external functions.
Sometimes it’s useful to access nested hash tables. H~> provides functionality for this by parsing any identifier containing dots. Each dot represents a sub-table entry.
For writes, if a subtable does not exist, it is created. However, if such creation would overwrite already-existing values, an error is thrown. For reads, non-existing subtables return #f.