Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

.Re: Map, Filter, and Reduce in Lisp

20 views
Skip to first unread message

Robert L.

unread,
Mar 26, 2022, 5:32:54 PM3/26/22
to
Vassil Nikolov wrote:

> | I'm familiar with map/filter/reduce from other languages. But I can't
> | find a simple doc on how to do these in Lisp! What I find perplexing
> | is that I thought that Lisp invented this paradigm?
>
> | What is the simplest way of map / filter / reducing a collection
> | (perhaps a list) in Lisp?
>
> I don't have a reference ready, but note that filtering in Common
> Lisp can be done with REMOVE, REMOVE-IF, and REMOVE-IF-NOT; here is a
> trivial example (one of many possible):
>
> (reduce #'+ (map 'list #'round (remove-if #'symbolp '(foo 1.2 bar 3.4
> baz 5.6))))
> => 10

Instead of CL, let's use a Lisp.

Gauche Scheme:

(fold + 0 (map round (remove symbol? '(foo 1.2 bar 3.4 baz 5.6))))

===>
10.0


0 new messages