Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.forth Subject: Re: Stack Operator Symbols Date: Sat, 29 Oct 2016 14:21:54 -0700 Organization: A noiseless patient Spider Lines: 32 Message-ID: <874m3un959.fsf@nightsong.com> References: <4e481228-bd80-4e39-a629-90a690e50756@googlegroups.com> <20161027191345.4f524e44@_> <-Lmdneii--uHXI_FnZ2dnUU7-VnNnZ2d@supernews.com> <87d1ijmwc3.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="34d41c0ea8a77aa9d2fd90d699221b0e"; logging-data="22108"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18g8jJMnHY6GbjBjHRQ/E7Z" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:ie7B3kwAHEhrzfHqCBzbO1OAJuA= sha1:Ljtimizb8to1tF6Por7AMkVZ+7k= Xref: csiph.com comp.lang.forth:52291 Andrew Haley writes: > first I'd try to understand how I got into a situation which needed 3DUP. I implemented the Tak function which is a widely used Lisp benchmark: https://en.wikipedia.org/wiki/Tak_(function) I wrote a Gforth version with and without locals: : tak-locals { x y z -- n} y x >= if z else x 1- y z recurse y 1- z x recurse z 1- x y recurse recurse then ; : 3dup ( a b c -- a b c a b c ) >r 2dup r@ -rot r> ; : tak ( x y z -- n ) -rot 2dup <= if 2drop ( z ) else ( z x y ) 3dup rot 1- -rot recurse >r \ tak (1- z) x y 3dup 1- -rot recurse >r \ tak (1- y) z x -rot 1- -rot recurse \ tak (1- x) y z r> r> recurse then ; : run 18 12 6 tak cr . cr ; Using 3dup seems natural here. Writing an asm version defeats the idea of benchmarking Forth with this function.