Path: ...!nx01.iad01.newshosting.com!newshosting.com!140.99.99.194.MISMATCH!news-in-02.newsfeed.easynews.com!easynews.com!easynews!sn-xt-sjc-02!sn-xt-sjc-08!sn-post-sjc-02!sn-post-sjc-01!supernews.com!news.supernews.com!not-for-mail From: Andrew Haley Newsgroups: comp.lang.forth Subject: Re: Factor, Postscript, and Forth: A case study Date: Fri, 04 May 2007 12:28:40 -0000 Message-ID: <133m9nohdhdje47@news.supernews.com> References: <2007May3.220119@mips.complang.tuwien.ac.at> User-Agent: tin/1.4.4-20000803 ("Vet for the Insane") (UNIX) (Linux/2.6.18-1.2798.fc6 (x86_64)) X-Complaints-To: abuse@supernews.com Lines: 34 In comp.lang.forth Anton Ertl wrote: > At the recent Forth-Tagung, Ulrich Hoffman gave a talk about Factor, a > language that's somewhere between Forth (mainly in syntax) and > Postscript (mainly in semantics, in particular the dynamic type > checking). > Eventually we decided to write and benchmark a small example in all > three languages: Generate an array of 1000 integers, then sum all the > elements 100000 times. > Here's the Forth version: > : map-array ( ... addr u xt -- ... ) > \ executes xt ( ... x -- ... ) for every element of the array starting > \ at addr and containing u elements > { xt } > cells over + swap ?do > i @ xt execute > 1 cells +loop ; The classic Forth way to do this would be with compiling words, not by passing an xt: : (map) ( a n - a a') cells over + swap ; : map[ postpone (map) postpone ?do ; immediate : ]map postpone cell postpone +loop ; immediate : step 0 array 1000 map[ + ]map drop ; I'm not saying that there's anything wrong with your map-array, but I don't think you'd write it that way unless trying to translate the idiom from another languyage into Forth. Andrew.