This fun macro has been in Arc Lisp from the start under the name accum, and I find it extremely useful. For example, I recently added support for list comprehensions using it: http://akkartik.name/post/list-comprehensions-in-anarki
One difference between the two: gathering uses a hardcoded function name gather, whereas accum takes a first arg that’s the function you call to ‘accumulate’ new item. Often we use acc, so calls begin (accum acc ...).
Serapeum has a version called collect too. I didn’t call it collect because that conflicts with iterate’s collect clause, and I tend to use iterate pretty heavily in my personal stuff..
For those that have tried to wipe the piece of salad from their phone screen, that is an image of a fern of some sort below the menu, not food on your screen.
This fun macro has been in Arc Lisp from the start under the name
accum, and I find it extremely useful. For example, I recently added support for list comprehensions using it: http://akkartik.name/post/list-comprehensions-in-anarkiOne difference between the two:
gatheringuses a hardcoded function namegather, whereasaccumtakes a first arg that’s the function you call to ‘accumulate’ new item. Often we useacc, so calls begin(accum acc ...).Interesting posr about list comprehensions!
It is commonly use collect or with-collector in Lisp. The named variant is also common.
https://github.com/jscl-project/jscl/blob/master/src/utils.lisp
There is even a variant to collect into multiple queues, in which case one has to provide a name for each collector.
Serapeum has a version called
collecttoo. I didn’t call itcollectbecause that conflicts with iterate’scollectclause, and I tend to use iterate pretty heavily in my personal stuff..Thanks for that pointer! I wasn’t aware, but in my toy lisp I called the pair
collectandyield. Glad I was on the right track!For those that have tried to wipe the piece of salad from their phone screen, that is an image of a fern of some sort below the menu, not food on your screen.
Macros: The Gathering