[Push] ps on DO*COUNT

Lee Spector lspector at hampshire.edu
Sun Feb 8 11:58:39 EST 2004


Just FYI, the new CODE.DO*COUNT instruction (which pops and executes 
the top piece of CODE the number of times indicated by the top INTEGER, 
pushing a counter that starts at 0 before each iteration) permits the 
following much simpler way to compute the factorial of a number on the 
INTEGER stack:

( CODE.QUOTE ( 1 INTEGER.+ INTEGER.* )
   1 INTEGER.SWAP CODE.DO*COUNT )

I just discovered this while writing up some Push2 stuff and thought 
I'd share the joy :-)

-Lee

--
Lee Spector
Dean, Cognitive Science + Associate Professor, Computer Science
Cognitive Science, Hampshire College, Amherst, MA 01002
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438





More information about the Push mailing list