Feedback requested on proposed new filter operator: "braid"

  1. “long”
    retains all input values while avoiding the creation of duplicate values, which is consistent with the “dominant append” handling applied by most other filter operators.
  2. “repeat”
    can produce duplicate values, which is similar to operators like enlist:raw[...] or get[...]. If “long” handling is the default, “repeat” could be a filter suffix (i.e., braid:repeat[...]). If “repeat” handling is the default, you could follow with a unique[] operator to produce the equivalent “long” result.
  3. “short”
    can omit values that were specified in the inputs, but still may be a useful result in some circumstances. If “long” handling is the default, this could also be a filter suffix (i.e. braid:short[...].

My suggestion is to use “long” handling by default, but permit all three variations in handling through the use of operator suffixes, like this:

  • braid:long[...],[...]
  • braid:repeat[...],[...]
  • braid:short[...],[...]

Also, as far as the name of the operator is concerned, “weave” or “plait” might be a decent alternative to “braid”.

-e

2 Likes

I like the intelectiual experimentation here, but think there exists better options to address the key value pairs and in fact the set manipulation functionality of this proposal. For example this is just a specific form of array manipulation, I would rather see a more generic solution manipulating arrays.

  • For example this thread discusses only the “braiding” of two two one dimensional arrays, what about the additions/multiplication of other arrays with more dimensions, unitary arrays, empty arrays and more.
  • Consider the existing functionality relating to widgets that accept names and values parameters

We need a coder, with mathematics and TiddlyWiki expierence. I only have a little of the first two.

I think my imagination exceeeds that of standard mathematics, an exploration using ChatGPT indicates they must have the same number of rows and columns, and the output such as a key=value pair is not a common result, arrays are then calculated.

  • I am confident that the code and algorithiums needed to write an array manipulation program would contain all the nessasary methods to solve arrays but also the formes needed for other solutions such as keyword value pairs, braiding etc…
  • This is all just part of greater subjects of “set manipulation” and possibly “graphs”.
1 Like

Very small nudge: “braid” just doesn’t do it for me as a metaphor here…

I expect a braid to have at least three elements, and for pairs within that order to swap relative positions. So a braid of “a b c” would involve playing with relative position such as “abc acb cab cba bca bac …”

As mentioned by @Scott_Sauyet it could be “zip”… but that could be messy because of the term’s use as file compression protocol. My own first reaction was: splice?

1 Like

There is trouble with both zip and splice in terms of expectations form other programming environments.

splice

In JS, splice is an operation on an array, clearly derived from the splicing of film. The first parameter is the index to start splicing out. The second is the number of items to remove. The remaining arguments are inserted in their place.

const bromide = ["cleanliness", "is", "next", "to", "godliness"]

bromide.splice(2, 2, "not", "anywhere", "near")  //=> returns ["next", "to"]

bromide  //=> now is ["cleanliness", "is", "not", "anywhere", "near", "godliness"]

This is my very least favorite JS method; the API is far too complex. But it is well-known and widely used.

zip

In many functional programming languages/libraries zip is used to take two lists of the same length and turn them into a list of pairs, one from each original list. An obvious extension allows us to start with n same-length lists, and turn that into a single list of n-tuples.

The trouble here is that the output is a list of lists, closely tied to a matrix transposition. This structure mostly inaccessible in TW.

// R is the Ramda library; other libraries and other languages are similar
R.zip([1, 2, 3], ["a", "b", "c"]) //=> [[1, "a"], [2, "b"], [3, "c"]]

Other options

While I don’t really object to braid, even though I do share your worry that it should involve at least three inputs. And I could live with weave. But I really prefer the original name of interleave. It’s more of a mouthful, but it’s descriptive and doesn’t come with as much baggage. And interlace is similar.

2 Likes

re: zip:

i don’t see this as too much of an issue, it won’t be compared to matrix functions if tw doesn’t have any. the output of the sample zip you give does seem very similar to the expected output of this new operator, and it would be expected to be extended in the same way. i think i like zip best out of the names proposed (as a programming dabbler / non-expert, the target audience?)
just my 2c on the naming.

1 Like

From a programmer’s perspective, these are two very different structures:

[1, 'a', 2, 'b', 3, 'c']
[[1, 'a'], [2, 'b'], [3, 'c']]

That latter seems difficult to express in TW, but it’s the usual expectation of a zip function.

This doesn’t mean that zip might not still be the best choice of names.

2 Likes