Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #20163
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Subject | Re: Filtering |
| Newsgroups | comp.lang.forth |
| Message-ID | <19189201008434@frunobulax.edu> (permalink) |
| Date | 2013-03-02 11:17 +0200 |
| References | <kgsasr0ibq@enews6.newsguy.com> |
| Organization | Wanadoo |
"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