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> Date: Sat, 2 Mar 2013 11:17:16 +0200 References: 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 "WJ" 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