3 ms·
Fun article. I'm somewhat still in the camp of loving Common Lisp's LOOP over many of the newer tools that are for looping over things. Articles like this do
by taeric 2y ago
Fun article. I'm somewhat still in the camp of loving Common Lisp's LOOP over many of the newer tools that are for looping over things. Articles like this do a good job of shining light on a lot of the concerns.
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. :(
- zappacino 2y agoAFAIK, the term was popularized by Rich Hickey in Clojure's implementation [1]. His talk introducing the concept goes into the etymology specifically. If I remember correctly it's something like "to carry across." [1] https://clojure.org/reference/transducers https://clojure.org/reference/transducers
- bjoli 2y agoTransducers are not loops. You can create transducers and pass them as arguments to functions, that in their turn can prepend or append then. They are composable algorithmic transformations.
- drcode 2y agocomposable algorithmic transformation in the streets but mostly an alternative to LOOP in the sheets
- bjoli 2y agoSure. But in that case it is somewhere between map(car)-and-friends and LOOP. 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.
- RhysU 2y ago> composable algorithmic transformations 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"?
- bjoli 2y agoThere are lots of examples of non-composable transformations. Two functions are not necessarily composable. Call/cc does not compose with the current continuation, whereas delimited continuations do. 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.
- deleted 2y ago[deleted]
- Zambyte 2y agoYou are correct with your question, SRFI 1[0] describes the knil argument as the "seed" or fold state (the latter for a recursive implementation). A sentinel value usually refers to a final value. Regarding the etymology: transform + reduce = transduce [0] https://srfi.schemers.org/srfi-1/srfi-1.html#fold https://srfi.schemers.org/srfi-1/srfi-1.html#fold
- darby_nine 2y agoI can't be alone in thinking that LOOP usage produces nearly unreadable code. It's extremely difficult to figure out what the intended behavior is if you don't have decades of reading them under your belt.
- taeric 2y agoMeh. It is like any other construct in this regard. If you let it get complicated, it can be complicated. Most of the time, you should be able to keep it short. Pointedly, though, it was hilarious to me how much Java began to look like typical LOOP constructs with Collectors.
- darby_nine 2y agoWhy not make multiple forms, then? The readability would certainly be increased if the writer were able to move beyond "loop". This smells more like for-loop insecurity than anything.
- taeric 2y agoI'm not sure I understand the question. If you think I was arguing against any new forms, that is a failing of my post. I am a fan of LOOP for places it works. I am also all for people exploring new things, and my intent on my post was to give credit in that direction.
- 0x3444ac53 2y agoI'm a fan of the ``` (let [ loop (fn [...] ```
- lkuty 2y agoIt is Clojure right? Does it imply a `recur` in the anonymous function? I don't really understand what the code will do since I only saw examples of `loop` with a condition. Why the `fn` ?
- 0x3444ac53 2y agoit's a scheme thing, not necessarily clojure. (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/ https://fennel-lang.org/ [2] http://www.phyast.pitt.edu/~micheles/scheme/scheme5.html#there-are-no-for-loops-in-scheme http://www.phyast.pitt.edu/~micheles/scheme/scheme5.html#the...
- ThatGeoGuy 2y agoQuick nit/question. For the fold method, I don't think I've seen it called sentinel value. Usually it is seed or initial? 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 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 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.
- lispm 2y agoI've seen the use of the word transducer first in SERIES, a Common Lisp library for iteration by Richard C. Waters. for example: https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node352.html#SECTION003423000000000000000 https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node352.html#...