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


Groups > comp.lang.forth > #45274

Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;

Newsgroups comp.lang.forth
Date 2016-02-03 06:19 -0800
References (8 earlier) <f1dcb775-9e78-4c67-afeb-91781371050d@googlegroups.com> <5ef3d7d6-c522-4c32-86b9-74713ccaa9b1@googlegroups.com> <3a8f6dd4-993e-4429-aedb-54399464ccbb@googlegroups.com> <56b1efed$0$23834$e4fe514c@news.xs4all.nl> <c2f9ca02-3d80-4314-9bc4-ed8ea3b1220e@googlegroups.com>
Message-ID <e596bccf-e42d-476c-86bf-e74e125d9869@googlegroups.com> (permalink)
Subject Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;
From humptydumpty <ouatubi@gmail.com>

Show all headers | View raw


On Wednesday, February 3, 2016 at 4:17:15 PM UTC+2, humptydumpty wrote:
> On Wednesday, February 3, 2016 at 2:17:51 PM UTC+2, Albert van der Horst wrote:
> > humptydumpty <> writes:
> > 
> > >On Wednesday, February 3, 2016 at 6:29:46 AM UTC+2, hughag...@gmail.com wro=
> > >te:
> > >> On Tuesday, February 2, 2016 at 12:36:47 AM UTC-7, humptydumpty wrote:
> > >> > The idea presented is beyond HOF.  To express it: "Words (functions) th=
> > >at return handles of themselves that can be used to call again that words (=
> > >functions), gives a alternative to think/use loops."
> > >>=20
> > >> Actually, you do have a good idea here that I didn't think of.=20
> > >>=20
> > >> This was my suggestion:
> > >>=20
> > >> \ toucher: i*x -- j*x continue?=20
> > >>=20
> > >> : YC ( xt -- )  >r begin  r@ execute while repeat  r> drop ;=20
> > >>=20
> > >> Your idea is that the word (I call it a "toucher" in my documentation) sh=
> > >ould return an xt or a FALSE rather than just a TRUE or a FALSE. The xt is =
> > >typically of itself. This is a good idea because it opens the door for to h=
> > >aving the toucher return the xt of another function rather than of itself. =
> > >For example, two of them could return each other's xt in order to alternate=
> > > back and forth.
> > >>=20
> > >> So, here is my new suggestion:
> > >>=20
> > >> \ toucher: i*x -- j*x xt|false
> > >>=20
> > >> : YC ( xt -- ) =20
> > >>     begin  execute  dup while repeat  drop ;
> > >>
> > 
> > >As suits your needs.  I think I make-up my mind about my proposition of YC:
> > 
> > >: YC    ( .. selfxt n -- .. )   BEGIN WHILE execute REPEAT drop ;
> > 
> > >        ,where n could be selfxt, a link, an data address, a count ...etc O=
> > >R 0 to stop the loop.
> > 
> > >=20
> > >> You still have the advantage that the data-stack is free of clutter when =
> > >the toucher executes, so it can access the data of the parent function. As =
> > >I've said 100 times here and elsewhere, this is essential. You now have the=
> > > additional advantage of one toucher staging another one, rather than itsel=
> > >f --- this is somewhat similar to a state-machine or a paced-loop in a micr=
> > >o-controller.
> > >>=20
> > >> The problem here is that we need to have LATEST available --- unfortunate=
> > >ly, the badly crippled ANS-Forth standard doesn't support LATEST so there i=
> > >s no easy way for the toucher to obtain its own xt.
> > >>=20
> > >> > In classic way I think of a loop as a *monolithic block* (ex.) BEGIN WH=
> > >ILE REPEAT that should be tested in its wholeness, in alternative way as *s=
> > >ingle-word* (hmm, like a server) and word that use it (like a client).
> > >> >=20
> > >> > I don't say that alternative way should substitute the classic way, but=
> > > may be a viable alternative when loop is too complex and hard to test.
> > >>=20
> > >> One advantage of a HOF is that the toucher can be tested in isolation. If=
> > > you write a loop explicitly all the code inside hasn't been factored out, =
> > >so there is no easy way to test it in isolation (I usually put a QUERY INTE=
> > >RPRET inside the loop to single-step through the loop; this was back in For=
> > >th-83 when we had QUERY and INTERPRET available).
> > >>=20
> > >> BTW: I really need to think of a better term than "toucher" --- I suspect=
> > > that everybody who reads that word imagines a pervert groping women in cro=
> > >wds.
> > 
> > The idea that the to be repeated action should return its own xt
> > could be extended with the idea that execution addresses belong
> > on the return stack. So
> > 
> > { .... } loop
> > { } puts an xt of sorts on the return stack.
> > Then loop executes that xt, until it is zero.
> > The IF EXIT THEN would be replaced by break? that replaces (
> > conditionally) the top of the return stack with a zero, a
> > very light action.
> > 
> 
> Looks that is implementation dependent. AFAIK gforth-itc and lina
> has in return-stack the xt of next word in definition:
> 
> : continuation R@ ;  ok                          
> ' dup :noname continuation dup drop @ ; execute = . -1  ok
> 
> But appears the problem of testing in isolation of step { ... },
> as '{ ... }' affects return-stack.
> 
> The only loops I founded using return-stack manipulations:
> 
> 1. The simplest way to provides loop using return-stack is
> 'continuation >R step-sequence-of-code R@ ;', exit with 'rdrop exit',
> continue with 'exit'.
> 
> 2. Another, a little more complex, generator-filter:
> 
> : ENTER         >R ;
> : |             IF EXIT THEN RDROP ;
> : START         BEGIN R@ ENTER AGAIN ;
> : STOP          IF RDROP RDROP RDROP THEN ;
> 
> I need to think more about that..
> 
> > :NONAME ... ;
> > could be replaced by
> > { ... } R>
> > 
> > >Uh oh! :-)  Maybe a "client", "using-word" ?
> > 
> > >Enjoying Forth,
> > >humptydumpty
> > -- 
> > 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
> 
> Enjoying Forth,
> humptydumpty

> 1. The simplest way to provides loop using return-stack is
> 'continuation >R step-sequence-of-code R@ ;', exit with 'rdrop exit',

> continue with 'exit'.
should be continue with 'R@ exit', sorry

humptydumpty

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

: YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-01-28 23:19 -0800
  Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-01-29 09:49 -0800
    Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-02-02 10:00 +0000
      Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-02-02 02:32 -0800
  Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; hughaguilar96@gmail.com - 2016-01-29 20:42 -0800
    Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-01-29 23:27 -0800
      Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-01-29 23:30 -0800
      Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; hughaguilar96@gmail.com - 2016-01-30 11:32 -0800
        Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-01-31 10:02 -0800
          Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; Julian Fondren <julian.fondren@gmail.com> - 2016-02-01 01:32 -0800
            Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-02-01 02:23 -0800
              Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; hughaguilar96@gmail.com - 2016-02-01 20:41 -0800
                Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-02-01 23:36 -0800
                Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; hughaguilar96@gmail.com - 2016-02-02 20:29 -0800
                Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-02-03 00:05 -0800
                Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-02-03 00:26 -0800
                Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-03 12:17 +0000
                Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-02-03 06:17 -0800
                Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-02-03 06:19 -0800
                Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; franck.bensusan@gmail.com - 2016-02-03 01:02 -0800
                Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; franck.bensusan@gmail.com - 2016-02-03 01:23 -0800
            Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-02 17:31 +0000
      Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; hughaguilar96@gmail.com - 2016-01-31 21:19 -0800
        Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-02-01 00:28 -0800
    Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; "WJ" <w_a_x_man@yahoo.com> - 2016-01-31 10:35 +0000
      Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; Chris Curl <ccurl609@gmail.com> - 2016-01-31 07:47 -0800
        Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; hughaguilar96@gmail.com - 2016-01-31 20:37 -0800
  Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; "WJ" <w_a_x_man@yahoo.com> - 2016-01-30 09:43 +0000
  Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; Julian Fondren <julian.fondren@gmail.com> - 2016-01-30 02:11 -0800
    Re: : YC  ( .. xt xt |0 -- .. )  BEGIN WHILE execute REPEAT ; humptydumpty <ouatubi@gmail.com> - 2016-01-30 11:33 -0800
    Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; "WJ" <w_a_x_man@yahoo.com> - 2016-01-31 10:11 +0000
      Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; Julian Fondren <julian.fondren@gmail.com> - 2016-01-31 08:04 -0800
        Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ; Julian Fondren <julian.fondren@gmail.com> - 2016-01-31 08:31 -0800

csiph-web