From: S. Robert James on 24 Feb 2007 21:14 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?
From: Pedro Kroger on 24 Feb 2007 21:30 On Feb 24, 11:14 pm, "S. Robert James" <srobertja...(a)gmail.com> wrote: > What is the simplest way of map / filter / reducing a collection > (perhaps a list) in Lisp? It depends on what you want to do. Have you looked for mapcar, mapcan, reduce, and many other mapping functions? [1] A few examples: (reduce #'+ '(1 2 3 4)) => 10 (mapcar #'sqrt '(1 2 3 4)) => (1.0 1.4142135 1.7320508 2.0) (mapcan #'(lambda (x) (if (oddp x) (list x))) '(1 2 3 4 5)) You should also take look at Practical Common Lisp [2]. Pedro Kroger [1] http://www.lisp.org/HyperSpec/Body/fun_mapccm_ma_istcm_mapcon.html [2] http://www.gigamonkeys.com/book/
From: Lars Rune Nøstdal on 24 Feb 2007 21:34 On Sat, 24 Feb 2007 18:14:48 -0800, S. Robert James 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? uhm .. have you checked the hyperspec? http://www.lispworks.com/documentation/HyperSpec/Front/index.htm http://www.lispworks.com/documentation/HyperSpec/Body/f_map.htm http://www.lispworks.com/documentation/HyperSpec/Body/f_reduce.htm `remove-if-not' is probably what you're after when you mention `filter': http://www.lispworks.com/documentation/HyperSpec/Body/f_rm_rm.htm you can download the hyperspec for offline reading here: http://www.lispworks.com/documentation/common-lisp.html) -- Lars Rune Nøstdal http://nostdal.org/
From: Vassil Nikolov on 24 Feb 2007 22:51 On 24 Feb 2007 18:14:48 -0800, "S. Robert James" <srobertjames(a)gmail.com> said: | 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 (see also MAPCAR). ---Vassil. -- Our programs do not have bugs; it is just that the users' expectations differ from the way they are implemented.
|
Pages: 1 Prev: Looking for implementation of Lisp / Scheme for mobile devices Next: A style question |