Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #49545
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Simple filtering |
| Date | 2016-07-26 18:37 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <nn8ako$clu$1@dont-email.me> (permalink) |
Barry Margolin wrote:
> In article ... (Christopher Dollin) writes:
> >So suppose someone says "please implement 'remove-if-not'. I would like
> >your solution to generate no garbage if possible and to be reasonably
> >efficient".
>
> Here's a version I threw together quickly (note that it doesn't take
> any options as the CL version does, and it only accepts a list, not
> any sequence):
>
> (defun simple-remove-if-not (test list)
> (let ((result nil))
> (dolist (item list)
> (unless (funcall test item)
> (push item result)))
> (nreverse result)))
OCaml:
open List ;;
let my_filter test list =
rev (fold_left
(fun result x -> if test x then x::result else result)
[]
list) ;;
my_filter (fun x -> 0=x mod 2) [0;2;3;4;5];;
===>
0; 2; 4]
my_filter (fun s -> String.length s > 2)
["a";"or";"and";"morose";"soar"] ;;
===>
["and"; "morose"; "soar"]
In Forth?
--
The former leader of the National Front Jean-Marie Le Pen was fined 30,000
euros for exposing the Jews Holocaust gas chamber hoax.
infostormer.com/jean-marie-le-pen-fined-30000-euros-for-exposing-jewish-holocaust-gas-chamber-hoax
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Simple filtering "WJ" <w_a_x_man@yahoo.com> - 2016-07-26 18:37 +0000
csiph-web