: (map) ( a n - a a') cells over + swap ; : map[ postpone (map) postpone ?do ; immediate : ]map 1 cells postpone literal postpone +loop ; immediate create array 1000 cells allot : init 1000 0 DO I array I cells + ! LOOP ; init : step 0 array 1000 map[ i @ + ]map drop ; : bench 100000 0 DO step LOOP ; bench \ Article: 127752 of comp.lang.forth \ Path: tunews.univie.ac.at!aconews-feed.univie.ac.at!newsfeed.wu-wien.ac.at!newsfeed.utanet.at!feeder1.cambrium.nl!feeder4.cambrium.nl!feeder5.cambrium.nl!feed.tweaknews.nl!63.218.45.10.MISMATCH!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 \ Xref: tunews.univie.ac.at comp.lang.forth:127752 \ 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.