Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #20163
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!postnews2.euro.net!news.wanadoo.nl!not-for-mail |
|---|---|
| From | mhx@iae.nl (Marcel Hendrix) |
| Subject | Re: Filtering |
| Newsgroups | comp.lang.forth |
| Message-ID | <19189201008434@frunobulax.edu> (permalink) |
| Date | Sat, 2 Mar 2013 11:17:16 +0200 |
| References | <kgsasr0ibq@enews6.newsguy.com> |
| X-Newsreader | iForth 2.0 console (October 21, 2006) |
| Lines | 31 |
| Organization | Wanadoo |
| NNTP-Posting-Date | 02 Mar 2013 10:16:50 GMT |
| NNTP-Posting-Host | s529d937f.adsl.online.nl |
| X-Trace | 1362219410 dr1.euro.net 53086 82.157.147.127:59313 |
| X-Complaints-To | abuse@wanadoo.nl |
| Xref | csiph.com comp.lang.forth:20163 |
Show key headers only | View raw
"WJ" <w_a_x_man@yahoo.com> writes Re: Filtering
> Given a sequence of numbers, keep those that are odd and
> multiply them by 100.
> Factor:
> USE: sequences.extras
> { 1 1 2 3 5 8 13 21 } [ odd? ] [ 100 * ] filter-map
> { 100 100 300 500 1300 2100 }
8 integer array x{ 1 1 2 3 5 8 13 21 x{ #=>
: fm ( x -- ) dup cdim 0 ?do dup i } @ dup 1 and if 100 * . else drop endif loop drop ;
x{ fm 100 100 300 500 1300 2100 ok
Or:
: fm BEGIN bl word dup C@
WHILE count evaluate dup 1 and IF 100 * . ELSE drop ENDIF
REPEAT drop ;
FORTH> fm 1 1 2 3 5 8 13 21 100 100 300 500 1300 2100 ok
FORTH> hex fm 1 f 2e 333 331 21fe 64 5DC 13FEC 13F24 ok
FORTH> fm %01 %1 #10 %11 %1001 %1000 #13 $15 100 100 300 900 1300 2100 ok
-marcel
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Filtering "WJ" <w_a_x_man@yahoo.com> - 2013-03-02 07:48 +0000
Re: Filtering mhx@iae.nl (Marcel Hendrix) - 2013-03-02 11:17 +0200
Re: Filtering "Charles Childers" <crc@retroforth.org> - 2013-03-02 11:18 -0500
Re: Filtering "A. K." <akk@nospam.org> - 2013-03-02 17:55 +0100
Re: Filtering Marc Olschok <nobody@nowhere.invalid> - 2013-03-03 22:11 +0000
csiph-web