News for hackers. Stuff that matters.
Re:Reflecting on Transducers in Scheme (2023) by taeric on Tuesday August 20, 2024 @05:07PM (#41304074)
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. :(

Re:Reflecting on Transducers in Scheme (2023) by zappacino on Tuesday August 20, 2024 @05:09PM (#41304097)
AFAIK, 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

Re:Reflecting on Transducers in Scheme (2023) by ThatGeoGuy on Tuesday August 20, 2024 @07:42PM (#41305228)
Quick 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

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.

Re:Reflecting on Transducers in Scheme (2023) by bjoli on Tuesday August 20, 2024 @05:10PM (#41304114)
Transducers 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.

Re:Reflecting on Transducers in Scheme (2023) by drcode on Tuesday August 20, 2024 @05:47PM (#41304431)
composable algorithmic transformation in the streets

but mostly an alternative to LOOP in the sheets

Re:Reflecting on Transducers in Scheme (2023) by bjoli on Tuesday August 20, 2024 @06:17PM (#41304675)
Sure. 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.

Re:Reflecting on Transducers in Scheme (2023) by RhysU on Tuesday August 20, 2024 @09:33PM (#41305910)
> 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"?

Re:Reflecting on Transducers in Scheme (2023) by bjoli on Wednesday August 21, 2024 @04:54AM (#41308252)
There 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.

Re:Reflecting on Transducers in Scheme (2023) by Zambyte on Tuesday August 20, 2024 @05:14PM (#41304144)
You 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

Re:Reflecting on Transducers in Scheme (2023) by darby_nine on Tuesday August 20, 2024 @07:14PM (#41305052)
I 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.
Re:Reflecting on Transducers in Scheme (2023) by taeric on Tuesday August 20, 2024 @07:25PM (#41305123)
Meh. 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.

Re:Reflecting on Transducers in Scheme (2023) by darby_nine on Wednesday August 21, 2024 @03:38AM (#41307759)
Why 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.

Re:Reflecting on Transducers in Scheme (2023) by taeric on Wednesday August 21, 2024 @12:00PM (#41311516)
I'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.
Re:Reflecting on Transducers in Scheme (2023) by 0x3444ac53 on Tuesday August 20, 2024 @07:28PM (#41305146)
I'm a fan of the ``` (let [ loop (fn [...] ```
Re:Reflecting on Transducers in Scheme (2023) by lkuty on Thursday August 22, 2024 @02:50AM (#41317512)
It 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` ?
Re:Reflecting on Transducers in Scheme (2023) by 0x3444ac53 on Monday August 26, 2024 @10:08AM (#41357270)
it'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/ [2] http://www.phyast.pitt.edu/~micheles/scheme/scheme5.html#the...

Re:Reflecting on Transducers in Scheme (2023) by lispm on Wednesday August 21, 2024 @01:57AM (#41307193)
I'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#...