Re: [Flashforth-devel] For-next and do-loop practise
Brought to you by:
oh2aun
|
From: Mikael N. <mik...@pp...> - 2011-06-16 14:59:08
|
Hi,
This is my untested quick take on this.
Of course if you are translating DO LOOP code
mechanically a direct template is good to have.
In general in FF I would not write code that
loops from A to B.
Usually I have a starting value A and a count N
Much code that uses do loops has the same and
must convert it to a A B=A+N pair before using the DO LOOP.
P is just a special variable which is saved on the return stack to
support nesting. J is implemented below without
nesting support. By saving it on the return stack
before FOR, it can also be made nestable.
-- Mike
On 16.6.2011 16:36, om1zz wrote:
> Hi, in order not to invent wheel (and maybe quite useful for other
> ffters too) I would ask the practisioners for an advice how to best
> translate following constructs into FF's for-next:
>
> a) B A do ... loop
B A - 1- for ... next
>
>
> b) B A do I ... loop
B A dup !p>r - 1- for @p p+ ... next r>p
>
>
> c) D C do
> B A do ... I J ... loop
> loop
variable j
D C dup !p>r - 1- for
B A dup j ! - 1- for
@p j @ ... p+ 1 j +!
next r>p
next
>
>
> d) B A do ... K +loop
B A - K / for ... next
>
>
> e) D C do
> B A do ... I J ... K +loop
> L +loop
variable j
D C dup !p>r - K / for
B A dup j ! L / for
@p j @ ... K p++ L j +!
next r>p
next
>
> f) B A ?do ... loop
B A - dup if 1- for ... next then
>
>
> Thanks,
> I.
>
>
|