3 ms·
It's better (by default) to optimize for programmer time and succinct expression unless something else takes priority, like running time, memory use, image size
by kazinator 11y ago
It's better (by default) to optimize for programmer time and succinct expression unless something else takes priority, like running time, memory use, image size, etc.
The TXR version of the iterative approach:
1> (let ((h (hash)))
(each ((c '(brown red green yellow yellow brown brown black)))
(inc [h c 0])) ;; (inc (gethash c h 0)) can be used
h)
#H(() (black 1) (yellow 2) (green 1) (red 1) (brown 3))
Or:
2> (let ((h (hash)))
(mapdo (do inc [h @1 0])
'(brown red green yellow yellow brown brown black))
h)
#H(() (black 1) (yellow 2) (green 1) (red 1) (brown 3))
I toyed with porting some loop macro implementation to TXR Lisp. I looked at some historic sources and just went "gack". Followed by, "what am I thinking".
I think in the end I would go for something like iterate, but even more Lispy. (Iterate still has "for x in y" type syntax in the clauses, just with parentheses around it; I would drop the infix "in" cruft and just have a symbol followed by nothing but semantic arguments)