Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wrote SRFI-171 for scheme. Ask me anything.

I have had many people tell me that the SRFI document [0] made transducers click for them, which is always a nice thing to hear.

0: https://srfi.schemers.org/srfi-171/srfi-171.html



An alternative, R7RS implementation that I also maintain for (CHICKEN) Scheme: <https://wiki.call-cc.org/eggref/5/transducers>

I believe I've submitted my own blog post on transducers in the past. See <https://www.thatgeoguy.ca/blog/2023/01/04/reflections-on-tra...>

To bjoli: Have you seen my library? Any intentions to update the SRFI and incorporate more types?


I have had some plans on updating the SRFI to add some reducers I did not include because I never actually used transducers before writing the initial implementation.

I don't really understand what you mean by types (my implementation stays monomorphic so new types are easily introduced by TYPE-transduce) , but I have thought about generalising things like numerical ranges by having something like unfold-transduce.


> but I have thought about generalising things like numerical ranges by having something like unfold-transduce.

This is more or less what I was wondering about. Numerics, ports, SRFI-41 streams, etc. There's a lot of stuff that isn't in e.g. r7rs-small but is more or less expected in most Scheme implementations.


Well. Without generic functions it is impossible to specify a "complete" API. I mention it in "Scope considerations" in the srfi document


OK. It's a better map that can keep some state. (I scanned not read your doc and that was my takeaway; I have not thought about what I can do with state yet, particularly since I had never associated transducers with being able to keep state)

Can you give me an example of a classic problem (since we're talking about transformations, raytracers and compilers come to mind) where if you involve a transducer vs a map you get an interesting difference?

Edit: 'How state is kept is not specified': I assume that there are limitations to state keeping, particularly with the composability and performance pillars of transducers, but I'm just having a really hard time synthesizing everything.


You could keep the state using the state monad, or by letting every reducer keep a transparent state in a linked list that whoever is pushing values through it has to handle. The reference implementation keeps it hidden using closures.

This is mostly an API thing. In clojure you can pass a transducer when you create a channel. That way you can make a channel do just about anything. Send data in chunks of N. Filter Odd numbers. Or just do arbitrary transformations.

It is a protocol for composable transformations of data being passed in one direction. It is not fancy. Not really hard to understand. A generalization of map, filter, and friends.


Regarding state: you can make thread safe transducers. The current SRFI 171 reference implementation is NOT thread safe. You can create a transducer and use it across different threads no problem. But you cannot start a transducer and use the returned reducer in different threads. It uses hidden mutable state.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: