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


Groups > comp.lang.forth > #45193

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

Newsgroups comp.lang.forth
Date 2016-01-29 23:30 -0800
References <090ad724-fdd4-4e5b-bacc-f1a6e6f32578@googlegroups.com> <7a996a61-993f-412d-bf17-b6744215a5a2@googlegroups.com> <2f129938-910a-4d50-8698-44530c57700b@googlegroups.com>
Message-ID <36386fed-e2eb-4afc-b73b-58f040e1b84f@googlegroups.com> (permalink)
Subject Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;
From humptydumpty <ouatubi@gmail.com>

Show all headers | View raw


On Saturday, January 30, 2016 at 9:27:25 AM UTC+2, humptydumpty wrote:
> On Saturday, January 30, 2016 at 6:42:19 AM UTC+2, hughag...@gmail.com wrote:
> > On Friday, January 29, 2016 at 12:19:28 AM UTC-7, humptydumpty wrote:
> > > : xt  latestxt postpone literal ; immediate
> > > 
> > > \ Use:     : wordname .... test-sequence IF xt dup ELSE 0 THEN ;
> > > \ Kick into action:     ' wordname dup YC
> > > 
> > > \ Example:
> > > : downcount     dup . 1- dup 0 >= IF xt dup ELSE 0 THEN ;
> > > 10 ' downcount dup YC drop
> > > 
> > > ---
> > > *Factored* loop. Small. Beautiful. Deserves to be a primitive.
> > > 
> > > Enjoying forth,
> > > humptydumpty
> > 
> > : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;
> > 
> > Here is an alternative suggestion:
> > 
> > \ toucher: i*x -- j*x continue?
> > 
> > : YC ( xt -- )  >r begin  r@ execute while repeat  r> drop ;
> > 
> > This way when your xt executes it has access to the data-stack that the parent set up (the i*x stuff) without anything (including its own xt value) being on top of this data getting in the way.
> > 
> > Also, we get rid of the DUP in your example code --- I found that to be quite confusing.
> > 
> > For the most part though, you are on the right track --- this is similar to the kind of code I have in my novice package --- I rely heavily on passing an xt into a HOF that does some iteration and executes the xt on every pass. :-)
> 
> 
> Hi!
> 
> Both methods gives transparency to data-stack, but responsibility to preserve
> 'xt' differs.
> 
> In my version, responsibility belongs to the word that is fed to the 'YC', in yours belongs to 'YC'.  My way does not clutter data-stack and can be used like
> this:
> 
> : guarded-counted-loop  ( .. xt xt |0 HiLim StartIdx -- .. )
>   DO
>     0= IF unloop EXIT THEN
>     execute
>   LOOP
> ;
> 
> About confusing 'DUP', is part of the game: the sequence 'dup execute'
> I see as indication of y-combinators in forth. Hence the name 'YC';
> is not a y-combinator (that provides recursion), is a factored-loop.
> 
> Enjoying forth,
> humptydumpty

OOPS!

Please, read 

> My way does not clutter data-stack and can be used like
> this:

as

"My way does not clutter RETURN-stack and can be used like this:"

Enjoying forth,
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