2

I would like to rewrite in scheme a script I made in clojure but I'm not sure how.

I wrote this simple script in clojure. It reads some csv files, processes them a bit and writes a new csv files.

It's based on a bunch of functions each accepting a map as an argument and returning a new map

The main loop uses the transducers. A transducer made of composing such functions in the right order. Like this

(def step1 (mapcat (comp
                    op/line-numbers
                    op/station
                    op/added-file-order
                    op/splitted-file
                    op/ingested-file)
                   )) 

The transducer is then made into a a lazy sequence. Like this

(defn thread [path]
  (sequence
        (comp step1 step2 step3 step4)
        (op/files-collection path)))

The sequence is then lazily written to a file.

I'm mumbling about implementing the same functionality (and in the future maybe more) in guile scheme

I know scheme has streams (as lazy sequences) but I'm not sure the semantics is the same as in clojure.

How would such a thing be made in scheme ? What's the idiomatic scheme version of such a thing ?

user1632812
  • 431
  • 3
  • 16
  • s/reducer/transducer/g ? – Arthur Ulfeldt Apr 06 '16 at 21:43
  • @ArthurUlfeldt yes, of course I confused them – user1632812 Apr 07 '16 at 18:30
  • 1
    You haven't gotten a response yet--maybe because there's not that much overlap between people who understand Scheme streams (perhaps a relatively small subset of the large Scheme community) and people who really understand Clojure transducers (growing, but still small, I'd guess). Still, I wonder if it would be better if you simplified your code to focus more directly on the core of your question about transducers and streams. (At first I wondered whether you wanted someone to show you how to implement `mapcat` in Scheme.) I'm barely in the transducer subset, never learned Scheme streams, btw. – Mars Apr 08 '16 at 04:09
  • @Mars thanks for your observations. The core of my question is not about transducers and streams. It's about processing a quite large bunch of csv files in guile scheme. As for transducers, I only used them in clojure because it seemed to me cool and convenient. I referred streams becaus the files are way larger than the memory on my computer so I tought the the way to go was with lazyness. But if the usual/idiomatic way in scheme to process large batches is different, then I'm all ears. – user1632812 Apr 08 '16 at 05:50
  • 1
    @Mars I actually understand Scheme streams very well, and I've looked at transducers a while ago and thought they were the bees' knees. So I'd be qualified to answer this question (heh, notwithstanding the OP's clarification that the question isn't really about streams or transducers). However, I'm also super busy and finding time to answer it has been challenging for me lately. But I have starred this question and will get to it when I can. – C. K. Young Apr 08 '16 at 14:47

0 Answers0