News for hackers. Stuff that matters.
Re:A History of Clojure [pdf] by gavinray on Thursday June 04, 2020 @11:25PM (#23424789)
It's less lines in JS/TS, depending on how you format the parens and braces.

    let csvData = [
      ["Name", "Age", "Email"],
      ["John", 25, "[email protected]"],
      ["Mary", 30, "[email protected]"],
      ["Anne", 40, "[email protected]"],
    ]

    let parseCSV = ([cols, ...rows]) => 
      rows.map(row => 
        row.reduce((res, val, i) => Object.assign(res, { [cols[i]]: val }), {}))


    parseCSV(csvData)
Re:A History of Clojure [pdf] by adamkl on Thursday June 04, 2020 @11:54PM (#23424934)
Yes, as I said in my original post (and others in this thread), you can absolutely come up with elegant solutions to this in other languages.

In my experience though, for every one elegant solution like yours, there will be ten developers writing nested for loops.

My example was never meant to be “look at what Clojure can do! You should all be jealous! “. Only an example of how Clojure encourages a different approach to solving problems that we are all familiar with.

Re:A History of Clojure [pdf] by dkersten on Friday June 05, 2020 @04:58AM (#23426434)
Its because the default abstractions provided as part of the language shape the way developers using that language approach problems. In Clojure, the sequence abstraction has been given a lot of thought and effort, which means that’s what Clojure developers will try to use. It also Clojure comes with a rich and powerful set if sequence functions which makes using sequences a breeze and lets you do super powerful things out if the box.

You could simply implement the exact same functions in other languages too and end up with similar code, butsince its not built in, most people won’t think in those abstractions.

Re:A History of Clojure [pdf] by gavinray on Friday June 05, 2020 @12:19AM (#23425039)
> there will be ten developers writing nested for loops.

Ain't that the forever truth =/

nested for loops go brrrrrr

Re:A History of Clojure [pdf] by onetom on Friday June 05, 2020 @09:16AM (#23428119)
Aaaand this works on arrays, but would you know how to make it work for files? You would need to do something like how the essay wrapped the `rdr` into a sequence, but it would still require (probably) the whole data to be present in the memory at once...

I think you would need something like this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

but I found it quite mind-bending when I tried it once. Clojure's way of building something like this out of a `lazy-seq` call feels simpler to me...

Re:A History of Clojure [pdf] by dunefox on Friday June 05, 2020 @04:08AM (#23426166)
I find that much less readable than Clojure.
Re:A History of Clojure [pdf] by dkersten on Friday June 05, 2020 @05:04AM (#23426475)
Is that due to familiarity or another reason?

I, too, find the Clojure version to be easier to read, but I spend more time with Clojure than JS.

Re:A History of Clojure [pdf] by dunefox on Friday June 05, 2020 @09:55AM (#23428541)
I'm not really familiar with either, I think the Clojure version just makes the intent clearer.