News for hackers. Stuff that matters.
Re:Magical, Mystical JavaScript Transducers by dan-robertson on Saturday June 29, 2019 @01:33AM (#20310957)
Because a bunch of those lines are concerned with the boring mechanics of how to compute this thing rather than what is being computed. It’s reasonable to say having a big system of composable transducers is pointless for one computation. It’s harder for 1000.

This point isn’t about transducers specifically but more about avoiding specifying the things you don’t care about. Eg, in Common Lisp (which was old enough to somewhat care about how to iterate things):

  (defun avg-popularity (list)
    (loop for item in list
      when (plusp (popularity item))
        sum pop into s
        count t into c
      finally (return (/ s c))))
This avoids having to care about the mechanics of how to sum or count things and I think it’s too sequential, when you don’t really care about that. One can certainly imagine a simpler to express solution in e.g. apl.
Re:Magical, Mystical JavaScript Transducers by TeMPOraL on Saturday June 29, 2019 @04:26AM (#20311452)
Note that to make it correct Common Lisp, you'd write it like that:

  (defun avg-popularity (list)
    (loop 
       for item in list
       for pop = (popularity item)
       when (plusp pop)
       sum pop into s
       and
       count t into c
       finally (return (/ s c))))
Two changes: 1) making `pop' be a thing, and 2) `when' clause of loop only applies to the next clause by default (here, `sum pop into s'), you need to include `and' to chain it with the next one so that both are guarded by `when' condition.