I think in Scheme it is common to call it knil, mirroring how lists use nil as the "sentinel" value which marks the end of a proper list. I opted to name it sentinel in that article (and in the docs) for two reasons:
1. Sentinel values are a common topic in many languages https://en.wikipedia.org/wiki/Sentinel_value
2. Transducers necessarily abstract across a lot more than loops / lists. Lisps do a lot of really cool (and optimized) stuff with lists alone and Scheme is no different in this regard. However, because of how Scheme primarily exports list operations in (scheme base) is really easy to run into a situation where lists are used in an ad-hoc way where another data structure is more appropriate. This includes vectors, sets, mappings, hashmaps, etc. Transducers-the-library is meant to be general across operations that work on all of these types, so I chose language that intentionally departs from thinking in a list-focused way.
Now, my main question. Transducer? I'm curious on the etymology of that word. By itself, I don't think I could ever guess what it was referencing. :(
This is from Rich Hickey's presentation: https://www.youtube.com/watch?v=6mTbuzafcII
It's not a reducer, because they serve as higher-order functions that operate on reducers. Instead, the values they accept are transient through the function(s), so they transduce. You should watch the video, I think Rich explains the origins of his language very well.
They are composable algorithmic transformations.
but mostly an alternative to LOOP in the sheets
Which is a situation where they add very little. Being able to use them as an intermediate step wherever data flows is probably the only place I use them myself. In channels, in file-readers etc. in places where you really need speed you should of course reach for whatever loop construct you prefer.
This phrasing always feels pointlessly fancy. I may be understeeped in the right lore.
What is a non-composable, non-algorithmic transformation? A composable, non-algorithmic transformation? A non-composable, algorithmic transformation?
Maybe there's some constraint on the domain vs the range buried in "transformation"?
Algorithmic transformations are algorithmic. The result is well-defined.
It is a succinct way of saying that a transducer is a well-defined (in terms of input and output) transformation that can be combined with other transducers.
I didn't make up the lingo.
Regarding the etymology: transform + reduce = transduce
Pointedly, though, it was hilarious to me how much Java began to look like typical LOOP constructs with Collectors.
This smells more like for-loop insecurity than anything.
(def foo '(1 2 3 4 5 6 7 8 9 10))
(let [loop (fn [x]
(if (empty? x) '()
(cons (+ 1 (car x)) (loop (cdr x)))))]
(loop foo)) ;=> (2 3 4 5 6 7 8 9 10 11)
It's just a way of simulating a loop with a recursive anonymous function within a let binding. As far as the fn, it's because lately I've been programming quite a lot in fennel[1] that borrows syntax from clojure. Although it should be said that this also isn't valid fennel code unless it's in a macro, but that's beside the pont.the (let [loop (fn ...)]) is something I learned here[2]
[1] https://fennel-lang.org/ [2] http://www.phyast.pitt.edu/~micheles/scheme/scheme5.html#the...
for example: https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node352.html#...
Quick nit/question. For the fold method, I don't think I've seen it called sentinel value. Usually it is seed or initial?
Now, my main question. Transducer? I'm curious on the etymology of that word. By itself, I don't think I could ever guess what it was referencing. :(