Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #9864 > unrolled thread

In Forth, is it valid or safe to use the value of 'I' after LOOP?

Started by"Rod Pemberton" <do_not_have@noavailemail.cmm>
First post2012-03-05 16:23 -0500
Last post2012-03-14 20:13 -0400
Articles 20 on this page of 102 — 20 participants

Back to article view | Back to comp.lang.forth


Contents

  In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-05 16:23 -0500
    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-05 12:11 -1000
      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-05 13:44 -1000
        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-06 11:26 +0000
          Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? rickman <gnuarm@gmail.com> - 2012-03-06 05:42 -0800
            Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-06 14:51 +0000
              Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-06 10:17 -0600
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-06 16:49 +0000
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-06 11:56 -0600
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-06 18:07 +0000
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-07 04:14 -0600
                        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-12 15:56 +0000
                          Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-12 11:23 -0500
                            Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-12 16:26 +0000
                              Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-12 12:28 -0500
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-06 13:36 -0500
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-06 09:18 -1000
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? hwfwguy@gmail.com - 2012-03-06 20:14 -0800
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-07 08:22 -0800
                        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? rickman <gnuarm@gmail.com> - 2012-03-07 10:20 -0800
                          Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-07 11:11 -0800
                        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? hwfwguy@gmail.com - 2012-03-07 19:07 -0800
                          Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-08 10:11 -0800
                          Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-12 09:36 +0000
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-12 16:01 +0000
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Alex McDonald <blog@rivadpm.com> - 2012-03-06 13:13 -0800
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-12 16:04 +0000
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-12 13:40 -0700
              Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? rickman <gnuarm@gmail.com> - 2012-03-07 10:15 -0800
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-07 10:33 -0800
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-07 17:16 -1000
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-12 11:18 +0000
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-12 08:01 -1000
            Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? jacko <jackokring@gmail.com> - 2012-03-15 18:59 -0700
              Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Coos Haak <chforth@hccnet.nl> - 2012-03-16 20:36 +0100
      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-06 13:33 -0500
        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-06 09:07 -1000
          Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-06 18:20 -0500
            Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-06 14:07 -1000
              Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? John Passaniti <john.passaniti@gmail.com> - 2012-03-06 16:53 -0800
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-06 19:26 -1000
              Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-10 19:04 -0500
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-10 18:44 -0800
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-11 17:06 -0400
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-11 17:01 -0700
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2012-03-11 12:51 +0000
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-11 14:04 -0700
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Paul Rubin <no.email@nospam.invalid> - 2012-03-11 14:41 -0700
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-12 05:16 -0500
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-12 08:06 -0700
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2012-03-11 21:55 +0000
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-11 17:17 -0700
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-12 11:00 +0000
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Josh Grams <josh@qualdan.com> - 2012-03-11 17:27 +0000
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Paul Rubin <no.email@nospam.invalid> - 2012-03-11 14:12 -0700
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Josh Grams <josh@qualdan.com> - 2012-03-11 21:48 +0000
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-11 14:24 -1000
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-11 17:09 -0700
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-11 17:34 -0400
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-11 13:18 -1000
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-11 17:32 -0700
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Josh Grams <josh@qualdan.com> - 2012-03-13 13:18 +0000
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-19 03:36 -0400
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? jacko <jackokring@gmail.com> - 2012-03-15 19:37 -0700
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-16 05:31 -0700
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-19 03:38 -0400
                        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-19 11:35 -0700
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Coos Haak <chforth@hccnet.nl> - 2012-03-16 20:39 +0100
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-03-12 12:50 -0700
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? jacko <jackokring@gmail.com> - 2012-03-15 19:27 -0700
            Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-07 08:16 -0800
            Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? jacko <jackokring@gmail.com> - 2012-03-15 19:09 -0700
    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? rickman <gnuarm@gmail.com> - 2012-03-05 14:23 -0800
    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? BruceMcF <agila61@netscape.net> - 2012-03-05 17:42 -0800
    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? hwfwguy@gmail.com - 2012-03-06 09:36 -0800
    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-08 10:41 +0000
    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-03-08 05:38 -0800
      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? hwfwguy@gmail.com - 2012-03-09 10:32 -0800
        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-03-12 19:26 -0700
        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-13 04:15 -0400
    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Coos Haak <chforth@hccnet.nl> - 2012-03-12 01:11 +0100
      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-12 19:41 -0400
        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-12 16:46 -1000
          Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-03-12 21:17 -0700
            Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-13 05:01 -0400
              Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-03-13 03:06 -0700
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Paul Rubin <no.email@nospam.invalid> - 2012-03-13 12:32 -0700
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-03-13 14:01 -0700
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Paul Rubin <no.email@nospam.invalid> - 2012-03-14 11:47 -0700
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "A. K." <akk@nospam.org> - 2012-03-14 22:13 +0100
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-14 03:39 -0500
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-14 06:54 -1000
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-03-14 16:39 -0700
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-15 10:49 +0000
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Alex McDonald <blog@rivadpm.com> - 2012-03-14 08:53 -0700
                    Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "A. K." <akk@nospam.org> - 2012-03-14 17:01 +0100
                      Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? George Hubert <georgeahubert@yahoo.co.uk> - 2012-03-14 11:21 -0700
                        Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "A. K." <akk@nospam.org> - 2012-03-14 19:25 +0100
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-03-14 16:37 -0700
                  Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-15 04:28 -0400
              Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "David N. Williams" <williams@umich.edu> - 2012-03-13 16:19 -0400
                Re: In Forth, is it valid or safe to use the value of 'I' after LOOP? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-14 20:13 -0400

Page 4 of 6 — ← Prev page 1 2 3 [4] 5 6  Next page →


#10032

FromBruceMcF <agila61@netscape.net>
Date2012-03-11 17:32 -0700
Message-ID<e87c19ec-9c79-492b-879f-389417a027e1@w29g2000yqw.googlegroups.com>
In reply to#10017
On Mar 11, 5:34 pm, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
wrote:
> Currently, I have IX as the variable for 'I' and LX as the variable
> for the loop limit.  'I' and (DO) and (LOOP) are:

>   : I IX @ ;
>   : (DO) IX ! LX ! ;
>   : (LOOP) 1 IX +! LX @ IX @ - 0= ;

> That works.  I think I did good in capturing the (undocumented) minus
> zero-equal termination condition of Forth loops.  Usually, the manuals
> say the termination is greater-than or equal ... (not).

You could use that. However, you need to modify (DO) to make it
reentrant and then add a cleanup word (given the above (DONE) would
fit.

2VARIABLE IX

: (DO) R> IX 2@ 2>R >R IX ! LX ! ;
: (DONE) R> 2R> IX 2! >R ;
: (LOOP) 1 IX +! IX 2@ - 0= ;
: J ['] R@ COMPILE, ; IMMEDIATE

K is not Forth94 CORE, you can simply omit it.

[toc] | [prev] | [next] | [standalone]


#10087

FromJosh Grams <josh@qualdan.com>
Date2012-03-13 13:18 +0000
Message-ID<4f5f4941$0$527$882e7ee2@usenet-news.net>
In reply to#10017
Rod Pemberton wrote: <jjj5pr$o84$1@speranza.aioe.org>
> Ok, let's start with what I have working and am currently using.  I have a
> single 'I' based DO-LOOP using variables.  DO and LOOP are setup similarly
> to fig-Forth (in Forth):
>
>  : DO COMPILE (DO) HERE ; IMMEDIATE
>  : LOOP COMPILE (LOOP) COMPILE 0BRANCH , ; IMMEDIATE
>
> Obviously, those compile (DO) and (LOOP) into the definitions.  Those may or
> may not need later modification either for I J K or for LEAVE or UNLOOP.
> I'm leaving those issues for later on.
>
> Currently, I have IX as the variable for 'I' and LX as the variable for the
> loop limit.  'I' and (DO) and (LOOP) are:
>
>  : I IX @ ;
>  : (DO) IX ! LX ! ;
>  : (LOOP) 1 IX +! LX @ IX @ - 0= ;
>
> That works.

Except that you can't ever have nested DO LOOPs.  You can't call any
word which uses a DO LOOP from inside a DO LOOP.  That seems like a
pretty significant problem to me.

> Of course, I first need to convert 'I' to a return stack method prior to
> implementing J K .  My first attempt at return stack based (DO) was:
>
>  : (DO) >R >R ;
>
> However, the parameters weren't where I expect them to be.  E.g., supposedly
> R@ can be used to get 'I' which indicates it is on the top (or bottom) of
> the stack.  In the definition above, it'd be 2nd instead of 1st.  So, next I
> added SWAP to (DO), and tried the following:

Yes, SWAP >R >R is generally a primitive under the name 2>R.

The theory is that the top element on the data stack is the one you most
often want to access, so it should be left on the top of the return
stack where it is most accessible.  Or something like that.

> I believed that should've worked.  However, my interpreter places another
> item on the return stack, i.e., when the interpreter enters (DO).  So,
> instead of being able to fetch 'I' using R@, I had to do this to I (DO) and
> (LOOP) to preserve another stack item:
>
>  : I R> R@ SWAP >R;
>  : (DO) R> SWAP ROT >R >R >R ;

Yeah, that's why they're generally primitives.  If you have an ALIAS
mechanism you could just define I as a new name for R@ without the colon
definition...

>  : (LOOP) R>  R> 1+ >R  R@ R> R@ -ROT >R  - 0=  SWAP >R ;
>
> I believe (LOOP) to be wrong.  It may just have a trivial error.  However, I
> got frustrated at about that point ...  So, I'll revisit it later.

Yeah, that's very hard to read, though it looks to me like it *is*
equivalent to your first definition.  Doing a straight translation from
variables to stack items is generally a bad idea.  Using double spaces
to break a word into "phrases" can also help readability:

: (LOOP) R>  R> R@ SWAP  1+ DUP >R - 0=  SWAP >R ;

--Josh

[toc] | [prev] | [next] | [standalone]


#10222

From"Rod Pemberton" <do_not_have@noavailemail.cmm>
Date2012-03-19 03:36 -0400
Message-ID<jk6nn1$qcb$1@speranza.aioe.org>
In reply to#10087
"Josh Grams" <josh@qualdan.com> wrote in message
news:4f5f4941$0$527$882e7ee2@usenet-news.net...
> Rod Pemberton wrote: <jjj5pr$o84$1@speranza.aioe.org>
> > [...]
> > I believed that should've worked.  However, my interpreter places
> > another item on the return stack, i.e., when the interpreter enters
> > (DO).  So, instead of being able to fetch 'I' using R@, I had to
> > do this to I (DO) and (LOOP) to preserve another stack item:
> >
> >  : I R> R@ SWAP >R;

This is a "syntax error".  There needs to be a space between >R and ;  ...

> > [...]
> >
> >  : (LOOP) R>  R> 1+ >R  R@ R> R@ -ROT >R  - 0=  SWAP >R ;
> >
> > I believe (LOOP) to be wrong.  It may just have a trivial error.

That definition for (LOOP) is actually correct for my ITC interpreter.  The
first part of the issue was due to the syntax error above.  The second is in
my reply to Bruce - loop parameters left on stack after exiting 0BRANCH in
LOOP.

> > [...]
>
> Yeah, that's very hard to read, though it looks to me like it *is*
> equivalent to your first definition.  Doing a straight translation from
> variables to stack items is generally a bad idea.  Using double spaces
> to break a word into "phrases" can also help readability:
>
> : (LOOP) R>  R> R@ SWAP  1+ DUP >R - 0=  SWAP >R ;

That's a better definition, also correct.  It "optimizes" better too.  I
reduce SWAP DUP and numerous "friends" to even lower level words.
Thanks.


Rod Pemberton



[toc] | [prev] | [next] | [standalone]


#10149

Fromjacko <jackokring@gmail.com>
Date2012-03-15 19:37 -0700
Message-ID<5639224.333.1331865422564.JavaMail.geo-discussion-forums@vbkc1>
In reply to#10017
On Sunday, March 11, 2012 9:34:18 PM UTC, Rod Pemberton wrote:
> "Josh Grams" <josh@qualdan.com> wrote in message
> news:4f5ce06b$0$6709$882e7ee2@usenet-news.net...
> > Rod Pemberton wrote: <jjgq7n$4j0$1@speranza.aioe.org>
> > > fig-Forth only has I not J and K.  fig-Forth uses primitive (low-level)
> > > words, i.e., (DO) and (LOOP) to implement runtime routines for DO and
> > > LOOP.  These manipulate items stacked on the return stack, not a
> > > variable. As primitives, these are not coded in Forth and so they don't
> > > push additional items onto the return stack.  My (DO) and (LOOP) are
> > > coded in Forth, and the interpreter pushes additional items onto the
> > > return stack.  Implementing I J K using the return stack will require
> > > working around those other stacked items.  So far, even with a
> > > stack-optimizer, their definitions are becoming long, complicated, and
> > > is still not working ...
> >
> > Can we see what you're doing?  It shouldn't be complicated.
> >
> > (DO) pushes the loop parameters (and whatever else) onto the rstack.
> > This `loop-sys` should be a fixed size.
> >
> > (LOOP) and (+LOOP) adjust the loop index on the rstack and either branch
> > back to the beginning of the loop or drop the parameters from the
> > rstack.
> >
> > Then I simply extracts the loop index from the parameters on the rstack,
> > and J and K do the same but from a fixed offset deeper in the rstack.
> >
> 
> Ok, let's start with what I have working and am currently using.  I have a
> single 'I' based DO-LOOP using variables.  DO and LOOP are setup similarly
> to fig-Forth (in Forth):
> 
>   : DO COMPILE (DO) HERE ; IMMEDIATE
>   : LOOP COMPILE (LOOP) COMPILE 0BRANCH , ; IMMEDIATE
> 



On Sunday, March 11, 2012 9:34:18 PM UTC, Rod Pemberton wrote:
> "Josh Grams" <josh@qualdan.com> wrote in message
> news:4f5ce06b$0$6709$882e7ee2@usenet-news.net...
> > Rod Pemberton wrote: <jjgq7n$4j0$1@speranza.aioe.org>
> > > fig-Forth only has I not J and K.  fig-Forth uses primitive (low-level)
> > > words, i.e., (DO) and (LOOP) to implement runtime routines for DO and
> > > LOOP.  These manipulate items stacked on the return stack, not a
> > > variable. As primitives, these are not coded in Forth and so they don't
> > > push additional items onto the return stack.  My (DO) and (LOOP) are
> > > coded in Forth, and the interpreter pushes additional items onto the
> > > return stack.  Implementing I J K using the return stack will require
> > > working around those other stacked items.  So far, even with a
> > > stack-optimizer, their definitions are becoming long, complicated, and
> > > is still not working ...
> >
> > Can we see what you're doing?  It shouldn't be complicated.
> >
> > (DO) pushes the loop parameters (and whatever else) onto the rstack.
> > This `loop-sys` should be a fixed size.
> >
> > (LOOP) and (+LOOP) adjust the loop index on the rstack and either branch
> > back to the beginning of the loop or drop the parameters from the
> > rstack.
> >
> > Then I simply extracts the loop index from the parameters on the rstack,
> > and J and K do the same but from a fixed offset deeper in the rstack.
> >
> 
> Ok, let's start with what I have working and am currently using.  I have a
> single 'I' based DO-LOOP using variables.  DO and LOOP are setup similarly
> to fig-Forth (in Forth):
> 
>   : DO COMPILE (DO) HERE ; IMMEDIATE
>   : LOOP COMPILE (LOOP) COMPILE 0BRANCH , ; IMMEDIATE
> 
> Obviously, those compile (DO) and (LOOP) into the definitions.  Those may or
> may not need later modification either for I J K or for LEAVE or UNLOOP.
> I'm leaving those issues for later on.
> 
> Currently, I have IX as the variable for 'I' and LX as the variable for the
> loop limit.  'I' and (DO) and (LOOP) are:
> 
>   : I IX @ ;
>   : (DO) IX ! LX ! ;
>   : (LOOP) 1 IX +! LX @ IX @ - 0= ;
> 
> That works.  I think I did good in capturing the (undocumented) minus
> zero-equal termination condition of Forth loops.  Usually, the manuals
> say the termination is greater-than or equal ... (not).
> 
> Of course, I first need to convert 'I' to a return stack method prior to
> implementing J K .  My first attempt at return stack based (DO) was:
> 
>   : (DO) >R >R ;
> 
> However, the parameters weren't where I expect them to be.  E.g., supposedly
> R@ can be used to get 'I' which indicates it is on the top (or bottom) of
> the stack.  In the definition above, it'd be 2nd instead of 1st.  So, next I
> added SWAP to (DO), and tried the following:
> 
>   : I R@ ;
>   : (DO) SWAP >R >R ;
>   : (LOOP) >R 1+ >R R@ R> R@ -ROT >R - 0= ;
> 
> I believed that should've worked.  However, my interpreter places another
> item on the return stack, i.e., when the interpreter enters (DO).  So,
> instead of being able to fetch 'I' using R@, I had to do this to I (DO) and
> (LOOP) to preserve another stack item:
> 
>   : I R> R@ SWAP >R;
>   : (DO) R> SWAP ROT >R >R >R ;
>   : (LOOP) R> R> 1+ >R R@ R> R@ -ROT >R - 0= SWAP >R ;
> 
> I believe (LOOP) to be wrong.  It may just have a trivial error.  However, I
> got frustrated at about that point ...  So, I'll revisit it later.
> 
> FYI, these are all in Forth as ASCII text as above and being parsed and
> defined by my Forth interpreter (which is pre-compiled Forth in C, like
> Forth in assembly).  The branches and stack operators are primitive
> (low-level) words and map to C routines.
> 
> Anyway, that's what I've done or attempted so far.  In a worst case
> scenario, I could implement (DO) (LOOP) and 'I' as primitives.
> 
> 
> Rod Pemberton



On Sunday, March 11, 2012 9:34:18 PM UTC, Rod Pemberton wrote:
> "Josh Grams" <josh@qualdan.com> wrote in message
> news:4f5ce06b$0$6709$882e7ee2@usenet-news.net...
> > Rod Pemberton wrote: <jjgq7n$4j0$1@speranza.aioe.org>
> > > fig-Forth only has I not J and K.  fig-Forth uses primitive (low-level)
> > > words, i.e., (DO) and (LOOP) to implement runtime routines for DO and
> > > LOOP.  These manipulate items stacked on the return stack, not a
> > > variable. As primitives, these are not coded in Forth and so they don't
> > > push additional items onto the return stack.  My (DO) and (LOOP) are
> > > coded in Forth, and the interpreter pushes additional items onto the
> > > return stack.  Implementing I J K using the return stack will require
> > > working around those other stacked items.  So far, even with a
> > > stack-optimizer, their definitions are becoming long, complicated, and
> > > is still not working ...
> >
> > Can we see what you're doing?  It shouldn't be complicated.
> >
> > (DO) pushes the loop parameters (and whatever else) onto the rstack.
> > This `loop-sys` should be a fixed size.
> >
> > (LOOP) and (+LOOP) adjust the loop index on the rstack and either branch
> > back to the beginning of the loop or drop the parameters from the
> > rstack.
> >
> > Then I simply extracts the loop index from the parameters on the rstack,
> > and J and K do the same but from a fixed offset deeper in the rstack.
> >
> 
> Ok, let's start with what I have working and am currently using.  I have a
> single 'I' based DO-LOOP using variables.  DO and LOOP are setup similarly
> to fig-Forth (in Forth):
> 
>   : DO COMPILE (DO) HERE ; IMMEDIATE
>   : LOOP COMPILE (LOOP) COMPILE 0BRANCH , ; IMMEDIATE
> 

: (LOOP) .... (0BRANCH) ;
: LOOP COMPILE (LOOP) , ; IMMEDIATE

ummmm

[toc] | [prev] | [next] | [standalone]


#10160

FromBruceMcF <agila61@netscape.net>
Date2012-03-16 05:31 -0700
Message-ID<a64a0235-463c-417c-86c4-ca96c87e1e37@h9g2000yqe.googlegroups.com>
In reply to#10017
On Mar 11, 5:34 pm, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
wrote:
> Ok, let's start with what I have working and am currently using.  I have a
> single 'I' based DO-LOOP using variables.  DO and LOOP are setup similarly
> to fig-Forth (in Forth):
>
>   : DO COMPILE (DO) HERE ; IMMEDIATE
>   : LOOP COMPILE (LOOP) COMPILE 0BRANCH , ; IMMEDIATE

Oh, yeah, and for this, the UNLOOP action would be included inside
(LOOP) based on the (LOOP)

>   : I IX @ ;
>   : (DO) IX ! LX ! ;
>   : (LOOP) 1 IX +! LX @ IX @ - 0= ;

On your pair of variables:

: I ( -- n ) IX @ ;

: (DO) ( n1 n2 -- )
   R> LX @ >R IX @ >R R> IX ! LX ! ;

: (LOOP) ( -- flag )
   1 IX +! LX @ IX @ - 0= DUP IF
      R> R> IX ! R> LX ! >R
   THEN ;

: J ( -- ) ( execute: -- n )
   POSTPONE R@ ; IMMEDIATE

... with IX as a double variable with the limit in the second cell:

: I ( -- n ) IX @ ;

: (DO) ( n1 n2 -- )
   R> IX 2@ 2>R R> IX 2! ;

: (LOOP) ( -- flag )
   1 IX +! IX 2@ - 0= DUP IF
      R> 2R> IX 2! >R
   THEN ;

: J ( -- n ) 2R@ DROP ; \ COMPILE-ONLY if you have it

[toc] | [prev] | [next] | [standalone]


#10223

From"Rod Pemberton" <do_not_have@noavailemail.cmm>
Date2012-03-19 03:38 -0400
Message-ID<jk6npl$qge$1@speranza.aioe.org>
In reply to#10160
"BruceMcF" <agila61@netscape.net> wrote in message
news:a64a0235-463c-417c-86c4-ca96c87e1e37@h9g2000yqe.googlegroups.com...
> On Mar 11, 5:34 pm, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
> wrote:
> > Ok, let's start with what I have working and am currently using. I have
> > a single 'I' based DO-LOOP using variables. DO and LOOP are setup
> > similarly to fig-Forth (in Forth):
> >
> > : DO COMPILE (DO) HERE ; IMMEDIATE
> > : LOOP COMPILE (LOOP) COMPILE 0BRANCH , ; IMMEDIATE
>
> Oh, yeah, and for this, the UNLOOP action would be included inside
> (LOOP) based on the (LOOP)

Yes, that was the second part of the problem.  Thanks.  The two loop
parameters are left on the return stack after exiting 0BRANCH.  Since the
threaded interpreter uses the top one as the return address for ENTER/EXIT,
it returned to invalid address ...

  : LOOP COMPILE (LOOP) COMPILE 0BRANCH , COMPILE (UNLOOP) ; IMMEDIATE

(UNLOOP) may not be the best name choice ...   I'll reconsider once I get
around to doing LEAVE and UNLOOP, etc.  (UNLOOP) removes the 2nd and 3rd
return stack items, i.e., the two loop parameters which are no longer
necessary.  The first return stack item is the return address for (UNLOOP)'s
ENTER/EXIT, due to the ITC interpreter.

The first part of the problem was a syntax error as noted in my reply to
Josh - no space between R> and ;


Rod Pemberton

[toc] | [prev] | [next] | [standalone]


#10236

FromBruceMcF <agila61@netscape.net>
Date2012-03-19 11:35 -0700
Message-ID<148b635e-42fd-44a5-a983-3c354421ddd1@m13g2000yqc.googlegroups.com>
In reply to#10223
On Mar 19, 3:38 am, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
wrote:
> "BruceMcF" <agil...@netscape.net> wrote in message
>
> news:a64a0235-463c-417c-86c4-ca96c87e1e37@h9g2000yqe.googlegroups.com...
>
> > On Mar 11, 5:34 pm, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
> > wrote:
> > > Ok, let's start with what I have working and am currently using. I have
> > > a single 'I' based DO-LOOP using variables. DO and LOOP are setup
> > > similarly to fig-Forth (in Forth):
>
> > > : DO COMPILE (DO) HERE ; IMMEDIATE
> > > : LOOP COMPILE (LOOP) COMPILE 0BRANCH , ; IMMEDIATE
>
> > Oh, yeah, and for this, the UNLOOP action would be included inside
> > (LOOP) based on the (LOOP)
>
> Yes, that was the second part of the problem.  Thanks.  The two loop
> parameters are left on the return stack after exiting 0BRANCH.  Since the
> threaded interpreter uses the top one as the return address for ENTER/EXIT,
> it returned to invalid address ...
>
>   : LOOP COMPILE (LOOP) COMPILE 0BRANCH , COMPILE (UNLOOP) ; IMMEDIATE
>
> (UNLOOP) may not be the best name choice ...   I'll reconsider once I get
> around to doing LEAVE and UNLOOP, etc.  (UNLOOP) removes the 2nd and 3rd
> return stack items, i.e., the two loop parameters which are no longer
> necessary.  The first return stack item is the return address for (UNLOOP)'s
> ENTER/EXIT, due to the ITC interpreter.
>
> The first part of the problem was a syntax error as noted in my reply to
> Josh - no space between R> and ;
>
> Rod Pemberton

From the other discussion on DO...LOOP, perhaps something along the
lines of the following, modified for BRANCH style definitions, would
work. Except for the LEAVE sketch, the original tested out on a system
with a single return stack entry on the called word on top of the
return stack of the caller ~ change those to 2R> and 2>R if there are
two entries:

--------------

VARIABLE leave-chain
0 leave-chain !

2VARIABLE IX

\ store old contents of IX on return stack
: (do) ( limit initial -- )
   R> IX 2@ 2>R >R OVER - IX 2! ;

: DO ( -- dest ) ( runtime: limit initial -- )
   leave-chain @ 0 leave-chain !
   POSTPONE (do) POSTPONE BEGIN ; IMMEDIATE

: I ( -- n ) IX 2@ + ;
: J ( -- n ) POSTPONE 2R@ POSTPONE + ; IMMEDIATE
: UNLOOP ( -- ) R> 2R> IX 2! >R ;

\ I think its something like this, unless I've got it turned around.
: LEAVE ( -- ) COMPILE BRANCH HERE leave-chain DUP @ , ! ; IMMEDIATE

: RAKE-LEAVES ( -- )
   HERE >R leave-chain @ BEGIN
      DUP WHILE
         DUP @ R@ ROT !
   REPEAT R> 2DROP ;

: (LOOP) ( -- )
   IX @ 1+ DUP IF IX ! FALSE EXIT THEN
   R> 2R> IX 2! >R TRUE ;

: (+LOOP) ( n -- )
   IX @ 2DUP XOR 0< >R
   TUCK + DUP IX ! XOR 0< R> AND IF
      R> 2R> IX 2! >R TRUE
   ELSE FALSE
   THEN ;

: LOOP ( -- )
   POSTPONE (LOOP) POSTPONE UNTIL
   RAKE-LEAVES leave-chain ! ; IMMEDIATE

: +LOOP ( n -- )
   \ implementation dependency on two's complement
   POSTPONE (+LOOP) POSTPONE UNTIL
   RAKE-LEAVES leave-chain ! ; IMMEDIATE

[toc] | [prev] | [next] | [standalone]


#10169

FromCoos Haak <chforth@hccnet.nl>
Date2012-03-16 20:39 +0100
Message-ID<o8gb86e054e8$.3rr3jm2p7h7u$.dlg@40tude.net>
In reply to#10017
Op Sun, 11 Mar 2012 17:34:18 -0400 schreef Rod Pemberton:

<snip>

>   : DO COMPILE (DO) HERE ; IMMEDIATE
>   : LOOP COMPILE (LOOP) COMPILE 0BRANCH , ; IMMEDIATE
> 
What would be here against:
: DO  POSTPONE (DO) POSTPONE BEGIN ; IMMEDIATE
: LOOP POSTPONE (LOOP) POSTPONE UNTIL ; IMMEDIATE

-- 
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html 

[toc] | [prev] | [next] | [standalone]


#10056

FromMark Wills <markrobertwills@yahoo.co.uk>
Date2012-03-12 12:50 -0700
Message-ID<fb502fd7-8547-49c1-a3c2-93ff2b58fb72@do4g2000vbb.googlegroups.com>
In reply to#9984
On Mar 11, 12:04 am, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
wrote:
> "Elizabeth D. Rather" <erat...@forth.com> wrote in messagenews:AO6dnfQQq64jO8vSnZ2dnUVZ_hSdnZ2d@supernews.com...
>
> > On 3/6/12 1:20 PM, Rod Pemberton wrote:
>
> > > The Forth looping mechanism *almost* seems perverse to me.
> > [...]
>
> Actually, it seems that I wasn't just being grumpy.
>
> I J K in Forth are even more complicated than first appearance.  The naming
> I J K is *relative* to the loop.  The naming is not fixed!  In other
> languages, the naming is fixed.  I.e., if K is used for the outer most of
> three loops, it's referenced as K in the middle and inner most loops also.
> They are variables.  For three nested loops in Forth, K in the inner most
> loop is J in the middle loop and is I in the outer most loop ... (sigh).
>
> E.g., apparently, this is correct in Forth:
>
> : T  5 0 DO I . 5 0 DO I . J . LOOP LOOP ;
>
> J in the inner loop is I in the outer loop.
>
> E.g., with fixed naming, or variables, or non-relative naming:
>
> : T  5 0 DO J . 5 0 DO I . J . LOOP LOOP ;
>
> J is J everywhere.
>
> fig-Forth only has I not J and K.  fig-Forth uses primitive (low-level)
> words, i.e., (DO) and (LOOP) to implement runtime routines for DO and LOOP.
> These manipulate items stacked on the return stack, not a variable.  As
> primitives, these are not coded in Forth and so they don't push additional
> items onto the return stack.  My (DO) and (LOOP) are coded in Forth, and the
> interpreter pushes additional items onto the return stack.  Implementing
> I J K using the return stack will require working around those other stacked
> items.  So far, even with a stack-optimizer, their definitions are becoming
> long, complicated, and is still not working ...
>
> However, not using variables for I J K and using the return stack means they
> are nameless, and relative too.  In which case, even though I J K are only
> specified after the DO, I shouldn't need to know which one is going to be
> used when DO occurs.  I think I'll have to come back to this issue at a
> later time.  For now, I'm going back to just having 'I' using a variable ...
>
> Rod Pemberton

I J & K are simply indexes into a stack that is holding information
pertinent to loops. It may or may not be the return stack.

In my system, I is:
MOV @2(RSTACK),*STACK+

and J is:
MOV @14(RSTACK),*STACK+

That's why I J & K "move". Because they are on a stack that get's
pushed and popped with "loop frames". It's simple enough once you get
the hang of it.

[toc] | [prev] | [next] | [standalone]


#10148

Fromjacko <jackokring@gmail.com>
Date2012-03-15 19:27 -0700
Message-ID<32109710.302.1331864823457.JavaMail.geo-discussion-forums@vbhv6>
In reply to#9984
On Sunday, March 11, 2012 12:04:33 AM UTC, Rod Pemberton wrote:
> "Elizabeth D. Rather" <erather@forth.com> wrote in message
> news:AO6dnfQQq64jO8vSnZ2dnUVZ_hSdnZ2d@supernews.com...
> > On 3/6/12 1:20 PM, Rod Pemberton wrote:
> > >
> > > The Forth looping mechanism *almost* seems perverse to me.
> > [...]
> 
> Actually, it seems that I wasn't just being grumpy.
> 
> I J K in Forth are even more complicated than first appearance.  The naming
> I J K is *relative* to the loop.  The naming is not fixed!  In other
> languages, the naming is fixed.  I.e., if K is used for the outer most of
> three loops, it's referenced as K in the middle and inner most loops also.
> They are variables.  For three nested loops in Forth, K in the inner most
> loop is J in the middle loop and is I in the outer most loop ... (sigh).
> 
> E.g., apparently, this is correct in Forth:
> 
> : T  5 0 DO I . 5 0 DO I . J . LOOP LOOP ;
> 
> J in the inner loop is I in the outer loop.
> 
> E.g., with fixed naming, or variables, or non-relative naming:
> 
> : T  5 0 DO J . 5 0 DO I . J . LOOP LOOP ;
> 
> J is J everywhere.
> 
> fig-Forth only has I not J and K.  fig-Forth uses primitive (low-level)
> words, i.e., (DO) and (LOOP) to implement runtime routines for DO and LOOP.
> These manipulate items stacked on the return stack, not a variable.  As
> primitives, these are not coded in Forth and so they don't push additional
> items onto the return stack.  My (DO) and (LOOP) are coded in Forth, and the
> interpreter pushes additional items onto the return stack.  Implementing
> I J K using the return stack will require working around those other stacked
> items.  So far, even with a stack-optimizer, their definitions are becoming
> long, complicated, and is still not working ...

The third stacked on R is the primary to be got or put. The second can be got by a subroutine nest, and also the first. 

[toc] | [prev] | [next] | [standalone]


#9912

FromBruceMcF <agila61@netscape.net>
Date2012-03-07 08:16 -0800
Message-ID<a601c48e-ed0e-4687-aa68-c0efaaaedd74@n12g2000yqb.googlegroups.com>
In reply to#9896
On Mar 6, 6:20 pm, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
wrote:
> Ah, now 6 we've dedicated words to do what Forth can do with a
> variable and three generic words.  We're definately on the "right"
> track with this looping thing guys!

Except it didn't happen like that, did it? It happened like
   A: "hey, here's a way to provide counted loops",
   B: "oh, yeah, I like how that works, lets see if I can add it to my
forth"
   C: "OK, I did it this way"
   D: "Oh, that's faster on my system, thanks".

Repeated. Some of this was going on in the wider world, in fig-
Dimensions and Dr. Dobbs, some of this was going on in small groups of
Forth programmers seeing each other face to face.

And much of what you are complaining about is the freedom for
different implementers to do things differently.

That is, if *you* wish to store the loop index and loop target on the
return stack directly, so that I and R@ are synonyms, just do it. But
if the language *specified* that R@ can get the stack index, you've
just *prevented* someone from using a do-loop frame of an offset index
on the -1/0 boundary or the max-pos / max-neg boundary with the second
element the offset ~ for some limited processors that's a big win in
terms of performance of simple counted loops. You've also *prevented*
someone from having an external RACK for space considerations but
using the hardware return stack for the do-loop stack frame for speed
considerations.

The only real behavioral issue, since a loop boundary has to be
*between* the target and one of its two neighbors, is whether +LOOP
halts on the same boundary for positive and negative increments, or on
the symmetric boundary. I'd rather it halts on the same boundary
either way, and -LOOP is available for the symmetric behavior. Some
people rather that +LOOP halts on the symmetric boundary for passing
from above rather than passing from below.

[toc] | [prev] | [next] | [standalone]


#10146

Fromjacko <jackokring@gmail.com>
Date2012-03-15 19:09 -0700
Message-ID<18438112.345.1331863752069.JavaMail.geo-discussion-forums@vbas10>
In reply to#9896
On Tuesday, March 6, 2012 11:20:36 PM UTC, Rod Pemberton wrote:
> "Elizabeth D. Rather" <erather@forth.com> wrote in message
> news:MMGdnUxDfcbF_cvSnZ2dnUVZ_s6dnZ2d@supernews.com...
> > On 3/6/12 8:33 AM, Rod Pemberton wrote:
> > >> "Elizabeth D. Rather"<erather@forth.com>  wrote in message
> > > news:1KGdnU2taaxgpMjSnZ2dnUVZ_hGdnZ2d@supernews.com...
> > >>> On 3/5/12 11:23 AM, Rod Pemberton wrote:
> > > [...]
> > >
> > >> I isn't a "variable" it's a word that pushes a *copy* of the current
> > >> value of the loop counter onto the stack when it is executed. Once on
> > >> the stack, it's like any other stack item, to use as you see fit.
> > >
> > > Yes, I noticed that ...  It seems that that also restricts the use of
> > > 'I' to do "skip counters" too.  [...] It seems one would need to setup
> > > a separate variable in Forth to perform the skip.
> >
> > If you need to manipulate the loop index, it's easy to do it with +LOOP.
> > That's what it's for.
> >
> 
> You don't find this mechanism clumsy or obtuse or awkward?
> 
> First, let us hide the loop counter behind a word that fetches it so no one
> can modify the counter directly.  Next, let's create another word that is
> used to add values to the counter since we no longer allow direct access to
> the counter.  Now, let's create another word so we can add some other value
> besides one to it, or well define LOOP in terms of +LOOP ...  Ah, only 3
> words to access the index.  That's clearly insufficient!  Oh, let's create J
> and K too, since implementing I by itself wasn't difficult enough.  Three
> loop counters should do it.  Also, let's require DO to initialize I, J, and
> K before we indicate which one we are going to use.  Now, that's a
> challenge! And, let's make it so J and K can only be used in nested DO
> LOOPS, respectively.  Now is DO hard enough for us to implement?  Ah, now 6
> we've dedicated words to do what Forth can do with a variable and three
> generic words.  We're definately on the "right" track with this looping
> thing guys!  Oh, we forgot a way to exit the loop: LEAVE.  The Forth looping
> mechanism *almost* seems perverse to me. But, hey, the cashier at McDonald's
> basically threw my money out the window and let the wind blow it away.  So,
> maybe I'm just cranky today.  If she stuffed it in her pocket, she'd be a
> thief!  I didn't get my money.  Isn't that the same?  Since I didn't get it
> and was owed it, can I claim they stole it?  That's the definition of
> stealing ... right?  Or, is shoving your hand out the window and letting go
> in the wind adequate and sufficient to comply with not "stealing" ones
> money?  Insanity, just like I J K DO LOOP +LOOP /LOOP -LOOP LEAVE ...
> When does it end? RfC for X Y Z *LOOP fibLOOP \LOOP :LOOP ;LOOP
> ?LOOP aLOOP bLOOP anyone?

'I @ .

[toc] | [prev] | [next] | [standalone]


#9866

Fromrickman <gnuarm@gmail.com>
Date2012-03-05 14:23 -0800
Message-ID<ad9e723e-0438-4de8-bf7a-1948ca42e43e@k6g2000vbz.googlegroups.com>
In reply to#9864
On Mar 5, 4:23 pm, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
wrote:
> In Forth, is it valid or safe to use the value of 'I' after LOOP?
>
> e.g., I need the termination value of the DO-LOOP at <x>:
>
> : some_def ... DO ... I ... LOOP <x> ... ;
>
> However, I'm not sure if it is valid and safe to use the termination value
> of 'I' there, like it would be in C.  My suspicion is: "No".  Use of a loop
> variable just after the loop,  IIRC ... , is common for other languages.
> How does Forth handle this?
>
> fig-Forth says other use of 'I', i.e., that outside a loop, is
> implementation dependent.
>
> ANS says an ambiguous condition exists if the loop control parameters are
> unvailable, but it doesn't state the loop control parameters are prohibited
> from use outside a loop.

You need to look at the definition of LOOP in the ANS document...

6.1.1800 LOOP CORE
...
An ambiguous condition exists if the loop control parameters are
unavailable. Add one to the loop index. If the loop index is then
equal to the loop limit, discard the loop parameters and
continue execution immediately following the loop. Otherwise continue
execution at the beginning of the loop.

The "loop control parameters" are gone outside of the loop.  LOOP
clears them when the count is satisfied.  So they can't be available
for I outside of the loop.


> Is it normal or rare in Forth that I is available after LOOP?

That I don't know.  I know the intent is that the "loop control
parameters" are implemented on a stack so you can nest and this is
often the return stack.  If the implementation were static rather than
on a stack the value could be accessed.


> Also, why does fig-Forth require ." in interactive mode, but ANS doesn't?

Fig-Forth?  I don't know much about that.

Rick


> Rod Pemberton
>
> WORDS
> WORDS 'LAST TRACE ID. ? LINK> NAME> BODY> >LINK >NAME>BODY ." (.") FILL ] [ CHAR LITERAL TYPE SPACES SPACE ALIGN
>
> ALIGNED CR VARIABLE CONSTANT CREATE DOES> ' ?DUP LOOP
> DO (LOOP) (DO) I UNTIL AGAIN BEGIN ELSE THEN IF NEGATE
> INVERT 1- 1+ C, ALLOT +! HERE CHARS CELLS CHAR+ CELL+
> TAKE NUP DIP DRIP -ROT TUCK NIP ROT OVER SWAP DROP DUP
> NOT TRUE FALSE SMUDGE ( IMMEDIATE B! B@ A! A@ nbSMDG
> nbPREC nbSIGN COLD ABORT QUIT INTERPRET ; : (CREATE) WORD
> QUERY COMPILE , 0BRANCH BRANCH TOGGLE OK XDUMP
> COMPARE COUNT CMOVE C! C@ EMIT KEY 0<> 0> 0< 0= < > <> =
> NUMBER - XOR OR AND EXECUTE FIND ENCLOSE TRIM EXPECT
> BYE LATEST +ofsPTR +ofsDLS +ofsPFA +ofsCFA +ofsNFA +ofsLFA
> szCELL szBYTE TIB NL LF BL LX IX STATE BLK IN RP0 SP0 RP SP
> DP0 DP LAST B A LIT . + ! @ R@ R> >R DODOES DOVAR ENTER EXIT
>
> There are some bugs, but it is coming along nicely now.

[toc] | [prev] | [next] | [standalone]


#9870

FromBruceMcF <agila61@netscape.net>
Date2012-03-05 17:42 -0800
Message-ID<22a4c0a3-8d6b-4def-aeca-f8ffd63d2c67@f4g2000yqh.googlegroups.com>
In reply to#9864
On Mar 5, 4:23 pm, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
wrote:
> In Forth, is it valid or safe to use the value of 'I' after LOOP?
>
> e.g., I need the termination value of the DO-LOOP at <x>:
>
> : some_def ... DO ... I ... LOOP <x> ... ;

VARIABLE LastI

: some_def ... DO ... I LastI ! ... LOOP ... LastI @ ...

[toc] | [prev] | [next] | [standalone]


#9885

Fromhwfwguy@gmail.com
Date2012-03-06 09:36 -0800
Message-ID<18501153.145.1331055402285.JavaMail.geo-discussion-forums@ynjk1>
In reply to#9864
On Monday, March 5, 2012 2:23:33 PM UTC-7, Rod Pemberton wrote:
> However, I'm not sure if it is valid and safe to use the termination value
> of 'I' there, like it would be in C.  My suspicion is: "No". 

Your suspicion is right. LOOP discards the loop parameters, so I after LOOP is meaningless, unless you have nested loops.

The loop stack may be the return stack or a separate loop stack, it could exploit hardware loop registers, and the indexing math can be set up to best exploit the ISA (so I <> R@). There is a lot of latitude in implementation.

-Brad

[toc] | [prev] | [next] | [standalone]


#9943

FromAlbert van der Horst <albert@spenarnc.xs4all.nl>
Date2012-03-08 10:41 +0000
Message-ID<m0kb15.n2k@spenarnc.xs4all.nl>
In reply to#9864
In article <jj3ats$bsb$1@speranza.aioe.org>,
Rod Pemberton <do_not_have@noavailemail.cmm> wrote:
>In Forth, is it valid or safe to use the value of 'I' after LOOP?

Of course not. The standard says: the system will crash if you
use I while the "loop parameters are not available", or words
to that intent.

>
>e.g., I need the termination value of the DO-LOOP at <x>:

If it terminates you can LEAVE. Then it is easy to remember
what I was

: .......   DO ....  IF ... I LEAVE THEN ... LOOP

< "explanation" SNIPPED>

If a loop parameter has meaning outside a loop, it probably is
in fact a variable

    VARIABLE _index

: ....     BEGIN    1 _index +! ...  WHILE ,,.   REPEAT
 .. _index .... ;


Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#9945

FromHugh Aguilar <hughaguilar96@yahoo.com>
Date2012-03-08 05:38 -0800
Message-ID<92b7f2c8-fc9c-4150-805e-b29939f6f2ff@x7g2000pbi.googlegroups.com>
In reply to#9864
On Mar 5, 2:23 pm, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
wrote:
> In Forth, is it valid or safe to use the value of 'I' after LOOP?

Nope, it isn't --- not in any Forth past, present or future.

When my Straight Forth comes out, I won't have DO loops at all.
Neither will I have >R R> R@ and all of that. I found this stuff to be
hugely complicated and error-prone when I was learning Forth 30 years
ago, and I still see novices struggling with it.

The I and J were essentially special-use local variables, invented by
Chuck Moore prior to the invention of general-purpose local variables.
The >R etc. words were also a weird hack invented prior to the
invention of general-purpose local variables. Straight Forth will just
have general-purpose local variables and BEGIN loops.

Straight Forth will get rid of all of this 1970s-vintage cruft. It
will be much leaner than ANS-Forth. On the other hand though, I will
add closures. I throw out a lot of old stuff, and add one new thing.

If people want to have a variable number of parameters on the stack
(usually with a zero underneath), they can just put that stuff into a
linked-list rather than on the stack. This is somewhat slower, but it
does work --- it is a pretty rare situation, so I'm not going to worry
about it too much.

[toc] | [prev] | [next] | [standalone]


#9964

Fromhwfwguy@gmail.com
Date2012-03-09 10:32 -0800
Message-ID<12556159.27.1331317954735.JavaMail.geo-discussion-forums@ynjk1>
In reply to#9945
On Thursday, March 8, 2012 6:38:06 AM UTC-7, Hugh Aguilar wrote:
> Straight Forth will just
> have general-purpose local variables and BEGIN loops.
> 
What would be the equivalent of "12 0 DO I . 3 +LOOP"?

> If people want to have a variable number of parameters on the stack
> (usually with a zero underneath), they can just put that stuff into a
> linked-list rather than on the stack. 

The "variable number of parameters" stack is what makes Forth Forth.

I agree that stack noise is undesirable. It will make your head hurt unless you're used to it. However, stack noise should be a small part of the application. The idea is to work toward an application that contains minimal stackrobatics.

The architecture of Forth and the semantics of each standard word were evaluated and reworked as a continuous process over decades of real world use. You can make your own "standard" but it won't go through that furnace of refinement.


[toc] | [prev] | [next] | [standalone]


#10075

FromHugh Aguilar <hughaguilar96@yahoo.com>
Date2012-03-12 19:26 -0700
Message-ID<48ee4060-7af0-4be9-8378-1714a03a0ff2@qb4g2000pbb.googlegroups.com>
In reply to#9964
On Mar 9, 12:32 pm, hwfw...@gmail.com wrote:
> On Thursday, March 8, 2012 6:38:06 AM UTC-7, Hugh Aguilar wrote:
> > If people want to have a variable number of parameters on the stack
> > (usually with a zero underneath), they can just put that stuff into a
> > linked-list rather than on the stack.
>
> The "variable number of parameters" stack is what makes Forth Forth.

I don't think you know what I'm talking about. See the words NON-ZEROS
REVERSE-STACK and DUP-STACK in the novice package for an example of
this stuff. It is rarely done.

> I agree that stack noise is undesirable. It will make your head hurt unless you're used to it. However, stack noise should be a small part of the application. The idea is to work toward an application that contains minimal stackrobatics.
>
> The architecture of Forth and the semantics of each standard word were evaluated and reworked as a continuous process over decades of real world use. You can make your own "standard" but it won't go through that furnace of refinement.

I'm not too impressed with this "furnace of refinement" that you speak
of --- I don't think that comp.lang.forth flame wars help in any way.

You won't find too much "stackrobatics" in the novice package. In some
cases I have two versions of words. One with local variables that is
slow but readable, and one with stackrobatics that is fast but
complicated. In Straight Forth, there won't be such a speed penalty
for using local variables as there is in SwiftForth, so I will use
locals more. On the other hand though, I think that recalcitrant C
programmers tend to overuse local variables in Forth --- I don't
encourage that.

[toc] | [prev] | [next] | [standalone]


#10080

From"Rod Pemberton" <do_not_have@noavailemail.cmm>
Date2012-03-13 04:15 -0400
Message-ID<jjmvp0$qvg$1@speranza.aioe.org>
In reply to#9964
<hwfwguy@gmail.com> wrote in message
news:12556159.27.1331317954735.JavaMail.geo-discussion-forums@ynjk1...
> [...]
> The "variable number of parameters" stack is what makes Forth Forth.
>

FYI, the "'variable number of parameters' stack" is formally called
0-operand:
http://en.wikipedia.org/wiki/Instruction_set#Number_of_operands
http://en.wikipedia.org/wiki/Model_of_computation


Rod Pemberton


[toc] | [prev] | [next] | [standalone]


Page 4 of 6 — ← Prev page 1 2 3 [4] 5 6  Next page →

Back to top | Article view | comp.lang.forth


csiph-web