2 ms·
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 h
by dan-robertson 7y ago
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.
- TeMPOraL 7y agoNote 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.