Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #53547
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Challenge for Christmas |
| Date | 2016-12-26 14:58 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2016Dec26.155852@mips.complang.tuwien.ac.at> (permalink) |
| References | (1 earlier) <2016Dec25.175253@mips.complang.tuwien.ac.at> <c87c7c04-7c90-4d38-84d2-996c42c27f1f@googlegroups.com> <o3p28k$65t$1@dont-email.me> <2016Dec26.142126@mips.complang.tuwien.ac.at> <2016Dec26.145757@mips.complang.tuwien.ac.at> |
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>Again, we see that the existing counted-loop words (including Gforth's
>U-DO ... -LOOP) are not a good fit striding backwards through an
>array. One would have to do the decrement first, and leave the loop
>when crossing the boundary between limit and limit-1. Maybe with a
>syntax like
>
>U-DO
> ( u ) DECREMENT
> ...
>REPEAT
>
>The code above would become:
>
>: product? ( n addr u -- )
> \ is n a product of the numbers in addr u?
> cells over + u-do
> cell decrement
> begin
> dup i @ /mod swap 0= while ( n1 n2 )
> nip repeat
> drop repeat
> 1 = ;
>
>The setup in front of the U-DO becomes quite a bit simpler.
Given that the convention for specifying arrays is "addr count", why
not simplify the setup even further and have
addr count stride A+DO ... A+LOOP \ i goes from addr...addr+(count-1)*stride
addr count stride A-DO ... A-LOOP \ i goes from addr+(count-1)*stride...addr
The example would become:
: product? ( n addr u -- )
\ is n a product of the numbers in addr u?
cell a-do ( n1 )
begin
dup i @ /mod swap 0= while ( n1 n2 )
nip repeat
drop a-loop
1 = ;
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2016: http://www.euroforth.org/ef16/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-24 06:10 -0800
Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-24 14:17 -0800
Re: Challenge for Christmas mhx@iae.nl - 2016-12-24 15:37 -0800
Re: Challenge for Christmas mhx@iae.nl - 2016-12-24 15:43 -0800
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 01:25 -0800
Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-25 06:59 -0800
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 07:26 -0800
Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-25 07:57 -0800
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 08:07 -0800
Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-25 08:25 -0800
Challenge for Christmas Ilya Tarasov <ilya74.tarasov@gmail.com> - 2016-12-25 07:39 -0800
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-25 16:52 +0000
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 09:33 -0800
Re: Challenge for Christmas Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-12-25 18:15 +0000
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 13:21 -0800
Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-25 16:51 -0800
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 00:48 -0800
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 01:36 -0800
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 01:39 -0800
Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-26 04:36 -0800
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 07:40 -0800
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-26 15:53 +0000
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 08:57 -0800
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-27 13:12 +0000
Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-27 16:58 +0100
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-27 16:01 +0000
Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-27 19:10 +0100
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-27 18:08 +0000
Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-27 20:13 +0100
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-28 08:19 +0000
Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-28 12:49 +0100
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-28 14:26 +0000
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-29 13:13 +0000
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-27 12:29 -0800
Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-27 22:25 +0100
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-27 14:19 -0800
Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-27 14:14 -0800
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-28 11:06 +0000
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-28 04:22 -0800
Re: Challenge for Christmas john <anon@example.com> - 2016-12-26 13:05 +0000
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 07:45 -0800
Re: Challenge for Christmas Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-12-26 07:44 +0000
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-26 13:21 +0000
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-26 13:57 +0000
Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-26 14:58 +0000
Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-26 17:24 +0100
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 09:15 -0800
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 11:45 -0800
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-30 10:47 -0800
Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-31 15:31 +0100
Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-31 10:53 -0800
csiph-web