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


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

How to solve this problem in FORTH?

Started bylehs <skydda.barnen@gmail.com>
First post2015-10-26 00:02 -0700
Last post2015-10-26 02:44 -0700
Articles 20 on this page of 32 — 14 participants

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  How to solve this problem in FORTH? lehs <skydda.barnen@gmail.com> - 2015-10-26 00:02 -0700
    Re: How to solve this problem in FORTH? Paul Rubin <no.email@nospam.invalid> - 2015-10-26 00:58 -0700
      Re: How to solve this problem in FORTH? lehs <skydda.barnen@gmail.com> - 2015-10-26 02:36 -0700
        Re: How to solve this problem in FORTH? Paul Rubin <no.email@nospam.invalid> - 2015-10-26 21:56 -0700
      Re: How to solve this problem in FORTH? Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-10-26 03:09 -0700
        Re: How to solve this problem in FORTH? Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-10-26 03:14 -0700
          Re: How to solve this problem in FORTH? lehs <skydda.barnen@gmail.com> - 2015-10-26 04:55 -0700
            Re: How to solve this problem in FORTH? Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-10-26 05:11 -0700
              Re: How to solve this problem in FORTH? humptydumpty <ouatubi@gmail.com> - 2015-10-26 06:35 -0700
                Re: How to solve this problem in FORTH? lehs <skydda.barnen@gmail.com> - 2015-10-26 12:25 -0700
                  Re: How to solve this problem in FORTH? humptydumpty <ouatubi@gmail.com> - 2015-10-27 00:47 -0700
                    Re: How to solve this problem in FORTH? lehs <skydda.barnen@gmail.com> - 2015-10-27 08:06 -0700
                      Re: How to solve this problem in FORTH? humptydumpty <ouatubi@gmail.com> - 2015-10-27 23:43 -0700
                        Re: How to solve this problem in FORTH? lehs <skydda.barnen@gmail.com> - 2015-10-28 01:30 -0700
                          Re: How to solve this problem in FORTH? humptydumpty <ouatubi@gmail.com> - 2015-10-28 01:58 -0700
                            Re: How to solve this problem in FORTH? franck.bensusan@gmail.com - 2015-10-28 02:56 -0700
                            Re: How to solve this problem in FORTH? lehs <skydda.barnen@gmail.com> - 2015-10-28 03:36 -0700
                        Re: How to solve this problem in FORTH? Hans Bezemer <the.beez.speaks@gmail.com> - 2015-10-28 15:31 +0100
        Re: How to solve this problem in FORTH? Paul Rubin <no.email@nospam.invalid> - 2015-10-26 21:58 -0700
          Re: How to solve this problem in FORTH? Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-10-26 23:38 -0700
          Re: How to solve this problem in FORTH? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-10-27 09:24 +0000
            Re: How to solve this problem in FORTH? Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-10-27 02:54 -0700
      Re: How to solve this problem in FORTH? mhx@iae.nl - 2015-10-26 11:31 -0700
    Re: How to solve this problem in FORTH? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-10-26 04:54 -0400
      Re: How to solve this problem in FORTH? Paul Rubin <no.email@nospam.invalid> - 2015-10-26 02:09 -0700
        Re: How to solve this problem in FORTH? Ron Aaron <rambamist@gmail.com> - 2015-10-26 11:16 +0200
        Re: How to solve this problem in FORTH? Lars Brinkhoff <lars.spam@nocrew.org> - 2015-10-26 10:49 +0100
        Re: How to solve this problem in FORTH? Hans Bezemer <the.beez.speaks@gmail.com> - 2015-10-28 11:22 +0100
          Re: How to solve this problem in FORTH? Howerd <howerdo@yahoo.co.uk> - 2015-10-28 04:09 -0700
          Re: How to solve this problem in FORTH? hughaguilar96@gmail.com - 2015-10-29 19:52 -0700
          Re: How to solve this problem in FORTH? "WJ" <w_a_x_man@yahoo.com> - 2015-10-30 09:00 +0000
      Re: How to solve this problem in FORTH? lehs <skydda.barnen@gmail.com> - 2015-10-26 02:44 -0700

Page 1 of 2  [1] 2  Next page →


#42820 — How to solve this problem in FORTH?

Fromlehs <skydda.barnen@gmail.com>
Date2015-10-26 00:02 -0700
SubjectHow to solve this problem in FORTH?
Message-ID<ed5ecb8e-cb01-4acb-9e4c-0a20b12f290b@googlegroups.com>
I think your solution is nice, but it's unfair comparing languages in such a limited perspective. In Forth arrays have a simple, not a complex and static,  implementation.
But what ever buillt in system other languages might have, any forther could extend Forth to be competitive.

[toc] | [next] | [standalone]


#42821

FromPaul Rubin <no.email@nospam.invalid>
Date2015-10-26 00:58 -0700
Message-ID<87fv0yvz6f.fsf@jester.gateway.sonic.net>
In reply to#42820
lehs <skydda.barnen@gmail.com> writes:
> I think your solution is nice, but it's unfair comparing languages in
> such a limited perspective. In Forth arrays have a simple, not a
> complex and static, implementation.

What would an idiomatic Forth implementation of a word like that be?
E.g. using a typical Forth array definition.

> But what ever built in system other languages might have, any forther
> could extend Forth to be competitive.

It's not too bad with gforth locals:

    : v& ( addr i -- addr ) cells + ;
    : vadd { v1 v2 v3 -- }
        3 0 do  v1 i v& @  v2 i v& @ +  v3 i v& !  loop ;

but it's not so well-factored, and fixing that is ugly as far as I can
tell.  It's one of those situations that makes me want nested functions
that can reach the parent's locals, sort of like the GCC nested function
extension:

    void vadd(int *v1, int *v2, int *v3) {
      void vk(int k) { v3[k] = v2[k] + v1[k]; }
      vk(0); vk(1); vk(2);
    }

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


#42828

Fromlehs <skydda.barnen@gmail.com>
Date2015-10-26 02:36 -0700
Message-ID<578b7a7e-0a4a-47b4-a347-8540ad26471c@googlegroups.com>
In reply to#42821
Den måndag 26 oktober 2015 kl. 08:58:34 UTC+1 skrev Paul Rubin:
> lehs <skydda.barnen@gmail.com> writes:
> > I think your solution is nice, but it's unfair comparing languages in
> > such a limited perspective. In Forth arrays have a simple, not a
> > complex and static, implementation.
> 
> What would an idiomatic Forth implementation of a word like that be?
> E.g. using a typical Forth array definition.
> 
> > But what ever built in system other languages might have, any forther
> > could extend Forth to be competitive.
> 
> It's not too bad with gforth locals:
> 
>     : v& ( addr i -- addr ) cells + ;
>     : vadd { v1 v2 v3 -- }
>         3 0 do  v1 i v& @  v2 i v& @ +  v3 i v& !  loop ;
> 
> but it's not so well-factored, and fixing that is ugly as far as I can
> tell.  It's one of those situations that makes me want nested functions
> that can reach the parent's locals, sort of like the GCC nested function
> extension:
> 
>     void vadd(int *v1, int *v2, int *v3) {
>       void vk(int k) { v3[k] = v2[k] + v1[k]; }
>       vk(0); vk(1); vk(2);
>     }

What I meant was that it seems rather easy to extend Forth into an all-purpose multidimensional array calculator where the top words could be very easy to understand - easy to understand what they are doing, but totally hidden how it is done.

I might try to develop "big-arrays" for ANS Forth and then wonder about the idiomatic implementation.
____________________
Lars-Erik Svahn
http://forthmath.blogspot.se
https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

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


#42862

FromPaul Rubin <no.email@nospam.invalid>
Date2015-10-26 21:56 -0700
Message-ID<8737wwx63d.fsf@jester.gateway.sonic.net>
In reply to#42828
lehs <skydda.barnen@gmail.com> writes:
> What I meant was that it seems rather easy to extend Forth into an
> all-purpose multidimensional array calculator where the top words
> could be very easy to understand - easy to understand what they are
> doing, but totally hidden how it is done.

Sounds like lots of design, implementation, debugging, maybe user
testing, etc. just to add two vectors together.  It might be possible to
sweep some messy code under the rug, but it's still there.

> I might try to develop "big-arrays" for ANS Forth and then wonder
> about the idiomatic implementation.

I'd like to see it.  It sounds complicated but might be worthwhile anyway.

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


#42831

FromRaimond Dragomir <raimond.dragomir@gmail.com>
Date2015-10-26 03:09 -0700
Message-ID<c790e466-39c8-44e9-9109-9e2524aacab2@googlegroups.com>
In reply to#42821
> It's not too bad with gforth locals:
> 
>     : v& ( addr i -- addr ) cells + ;
>     : vadd { v1 v2 v3 -- }
>         3 0 do  v1 i v& @  v2 i v& @ +  v3 i v& !  loop ;
> 
> but it's not so well-factored, and fixing that is ugly as far as I can
> tell.  It's one of those situations that makes me want nested functions
> that can reach the parent's locals, sort of like the GCC nested function
> extension:
> 
>     void vadd(int *v1, int *v2, int *v3) {
>       void vk(int k) { v3[k] = v2[k] + v1[k]; }
>       vk(0); vk(1); vk(2);
>     }

Why would you need a nested function for such a trivial problem?
Anyway, here it is a solution with and without a nested function, 
(a quotation) in my forth:

&&&
void vadd(int *v1, int *v2, int *v3)
{
  v3[0] = v1[0] + v2[0];
  v3[1] = v1[1] + v2[1];
  v3[2] = v1[2] + v2[2];
}
&

: th \ base index -- value
  cells + ;

: vadd1
  local{ v1 v2 v3 }
  v1 @ 0 th @  v2 @ 0 th @  v3 @ 0 th !
  v1 @ 1 th @  v2 @ 1 th @  v3 @ 1 th !
  v1 @ 2 th @  v2 @ 2 th @  v3 @ 2 th !
;

: vadd2
  local{ v1 v2 v3 | vadd }
  { >r v1 @ r@ th @  v2 @ r@ th @  v3 @ r> th ! } vadd !
  0 vadd @ execute
  1 vadd @ execute
  2 vadd @ execute
;

\ test
const V1 1 , 2 , 3 ,
const V2 4 , 5 , 6 ,
3 cells var V3
V1 V2 V3 vadd1
." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr

V1 V2 V3 vadd1
." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr

result vadd1: 4 5 6
result vadd2: 4 5 6
 ok

It uses the famous "th" at the base, but otherwise it's quite clean.
No dup drop swap over rot...

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


#42832

FromRaimond Dragomir <raimond.dragomir@gmail.com>
Date2015-10-26 03:14 -0700
Message-ID<8a16e44e-0fa3-416e-a345-2bc50b135073@googlegroups.com>
In reply to#42831
luni, 26 octombrie 2015, 12:09:16 UTC+2, Raimond Dragomir a scris:
> > It's not too bad with gforth locals:
> > 
> >     : v& ( addr i -- addr ) cells + ;
> >     : vadd { v1 v2 v3 -- }
> >         3 0 do  v1 i v& @  v2 i v& @ +  v3 i v& !  loop ;
> > 
> > but it's not so well-factored, and fixing that is ugly as far as I can
> > tell.  It's one of those situations that makes me want nested functions
> > that can reach the parent's locals, sort of like the GCC nested function
> > extension:
> > 
> >     void vadd(int *v1, int *v2, int *v3) {
> >       void vk(int k) { v3[k] = v2[k] + v1[k]; }
> >       vk(0); vk(1); vk(2);
> >     }
> 
> Why would you need a nested function for such a trivial problem?
> Anyway, here it is a solution with and without a nested function, 
> (a quotation) in my forth:
> 
> &&&
> void vadd(int *v1, int *v2, int *v3)
> {
>   v3[0] = v1[0] + v2[0];
>   v3[1] = v1[1] + v2[1];
>   v3[2] = v1[2] + v2[2];
> }
> &
> 
> : th \ base index -- value
>   cells + ;
> 
> : vadd1
>   local{ v1 v2 v3 }
>   v1 @ 0 th @  v2 @ 0 th @  v3 @ 0 th !
>   v1 @ 1 th @  v2 @ 1 th @  v3 @ 1 th !
>   v1 @ 2 th @  v2 @ 2 th @  v3 @ 2 th !
> ;
> 
> : vadd2
>   local{ v1 v2 v3 | vadd }
>   { >r v1 @ r@ th @  v2 @ r@ th @  v3 @ r> th ! } vadd !
>   0 vadd @ execute
>   1 vadd @ execute
>   2 vadd @ execute
> ;
> 
> \ test
> const V1 1 , 2 , 3 ,
> const V2 4 , 5 , 6 ,
> 3 cells var V3
> V1 V2 V3 vadd1
> ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> 
> V1 V2 V3 vadd1
> ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> 
> result vadd1: 4 5 6
> result vadd2: 4 5 6
>  ok
> 
> It uses the famous "th" at the base, but otherwise it's quite clean.
> No dup drop swap over rot...

LOL, I forgot the "+"...

: th \ base index -- value
  cells + ;

: vadd1
  local{ v1 v2 v3 }
  v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
  v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
  v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
;

: vadd2
  local{ v1 v2 v3 | vadd }
  { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
  0 vadd @ execute
  1 vadd @ execute
  2 vadd @ execute
;

\ test
const V1 1 , 2 , 3 ,
const V2 4 , 5 , 6 ,
3 cells var V3
V1 V2 V3 vadd1
." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr

V1 V2 V3 vadd1
." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr

result vadd1: 5 7 9
result vadd2: 5 7 9
 ok

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


#42842

Fromlehs <skydda.barnen@gmail.com>
Date2015-10-26 04:55 -0700
Message-ID<c3ec2a57-3199-4dba-9174-df232d62c93d@googlegroups.com>
In reply to#42832
Den måndag 26 oktober 2015 kl. 11:14:54 UTC+1 skrev Raimond Dragomir:
> luni, 26 octombrie 2015, 12:09:16 UTC+2, Raimond Dragomir a scris:
> > > It's not too bad with gforth locals:
> > > 
> > >     : v& ( addr i -- addr ) cells + ;
> > >     : vadd { v1 v2 v3 -- }
> > >         3 0 do  v1 i v& @  v2 i v& @ +  v3 i v& !  loop ;
> > > 
> > > but it's not so well-factored, and fixing that is ugly as far as I can
> > > tell.  It's one of those situations that makes me want nested functions
> > > that can reach the parent's locals, sort of like the GCC nested function
> > > extension:
> > > 
> > >     void vadd(int *v1, int *v2, int *v3) {
> > >       void vk(int k) { v3[k] = v2[k] + v1[k]; }
> > >       vk(0); vk(1); vk(2);
> > >     }
> > 
> > Why would you need a nested function for such a trivial problem?
> > Anyway, here it is a solution with and without a nested function, 
> > (a quotation) in my forth:
> > 
> > &&&
> > void vadd(int *v1, int *v2, int *v3)
> > {
> >   v3[0] = v1[0] + v2[0];
> >   v3[1] = v1[1] + v2[1];
> >   v3[2] = v1[2] + v2[2];
> > }
> > &
> > 
> > : th \ base index -- value
> >   cells + ;
> > 
> > : vadd1
> >   local{ v1 v2 v3 }
> >   v1 @ 0 th @  v2 @ 0 th @  v3 @ 0 th !
> >   v1 @ 1 th @  v2 @ 1 th @  v3 @ 1 th !
> >   v1 @ 2 th @  v2 @ 2 th @  v3 @ 2 th !
> > ;
> > 
> > : vadd2
> >   local{ v1 v2 v3 | vadd }
> >   { >r v1 @ r@ th @  v2 @ r@ th @  v3 @ r> th ! } vadd !
> >   0 vadd @ execute
> >   1 vadd @ execute
> >   2 vadd @ execute
> > ;
> > 
> > \ test
> > const V1 1 , 2 , 3 ,
> > const V2 4 , 5 , 6 ,
> > 3 cells var V3
> > V1 V2 V3 vadd1
> > ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > 
> > V1 V2 V3 vadd1
> > ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > 
> > result vadd1: 4 5 6
> > result vadd2: 4 5 6
> >  ok
> > 
> > It uses the famous "th" at the base, but otherwise it's quite clean.
> > No dup drop swap over rot...
> 
> LOL, I forgot the "+"...
> 
> : th \ base index -- value
>   cells + ;
> 
> : vadd1
>   local{ v1 v2 v3 }
>   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
>   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
>   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> ;
> 
> : vadd2
>   local{ v1 v2 v3 | vadd }
>   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
>   0 vadd @ execute
>   1 vadd @ execute
>   2 vadd @ execute
> ;
> 
> \ test
> const V1 1 , 2 , 3 ,
> const V2 4 , 5 , 6 ,
> 3 cells var V3
> V1 V2 V3 vadd1
> ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> 
> V1 V2 V3 vadd1
> ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> 
> result vadd1: 5 7 9
> result vadd2: 5 7 9
>  ok

Why not factorize the nested function?

: th_add ( v1 v2 v3 i -- )
  2>r r@ th @ swap r@ th @ + 2r> th !
;

: vadd
  local{ v1 v2 v3 } 
  v1 v2 v3 0 th_add 
  v1 v2 v3 1 th_add
  v1 v2 v3 2 th_add
; 
____________________
Lars-Erik Svahn
http://forthmath.blogspot.se
https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

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


#42843

FromRaimond Dragomir <raimond.dragomir@gmail.com>
Date2015-10-26 05:11 -0700
Message-ID<12ca995c-dedd-468e-8b01-ce593ab22dc3@googlegroups.com>
In reply to#42842
> Why not factorize the nested function?
> 
> : th_add ( v1 v2 v3 i -- )
>   2>r r@ th @ swap r@ th @ + 2r> th !
> ;
> 
> : vadd
>   local{ v1 v2 v3 } 
>   v1 v2 v3 0 th_add 
>   v1 v2 v3 1 th_add
>   v1 v2 v3 2 th_add
> ; 
> ____________________
> Lars-Erik Svahn
> http://forthmath.blogspot.se
> https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

My vadd2 (with the quotation) is something like that.
I added your variant at the end, but I used only locals for the intermediate
vadd (your th_add):

: th \ base index -- value
  cells + ;

: vadd1
  local{ v1 v2 v3 }
  v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
  v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
  v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
;

: vadd2
  local{ v1 v2 v3 | vadd }
  { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
  0 vadd @ execute
  1 vadd @ execute
  2 vadd @ execute
;

\ test
const V1 1 , 2 , 3 ,
const V2 4 , 5 , 6 ,
3 cells var V3
V1 V2 V3 vadd1
." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr

V1 V2 V3 vadd2
." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr

: vadd
  local{ v1 v2 v3 i }
  v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;

: vadd3
  local{ v1 v2 v3 }
  v1 @ v2 @ v3 @ 0 vadd
  v1 @ v2 @ v3 @ 1 vadd
  v1 @ v2 @ v3 @ 2 vadd
;

V1 V2 V3 vadd3
." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr

result vadd1: 5 7 9
result vadd2: 5 7 9
result vadd3: 5 7 9
 ok

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


#42848

Fromhumptydumpty <ouatubi@gmail.com>
Date2015-10-26 06:35 -0700
Message-ID<e078bd6f-6750-43b7-9a57-c4475baedf9f@googlegroups.com>
In reply to#42843
On Monday, October 26, 2015 at 2:11:01 PM UTC+2, Raimond Dragomir wrote:
> > Why not factorize the nested function?
> > 
> > : th_add ( v1 v2 v3 i -- )
> >   2>r r@ th @ swap r@ th @ + 2r> th !
> > ;
> > 
> > : vadd
> >   local{ v1 v2 v3 } 
> >   v1 v2 v3 0 th_add 
> >   v1 v2 v3 1 th_add
> >   v1 v2 v3 2 th_add
> > ; 
> > ____________________
> > Lars-Erik Svahn
> > http://forthmath.blogspot.se
> > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> 
> My vadd2 (with the quotation) is something like that.
> I added your variant at the end, but I used only locals for the intermediate
> vadd (your th_add):
> 
> : th \ base index -- value
>   cells + ;
> 
> : vadd1
>   local{ v1 v2 v3 }
>   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
>   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
>   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> ;
> 
> : vadd2
>   local{ v1 v2 v3 | vadd }
>   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
>   0 vadd @ execute
>   1 vadd @ execute
>   2 vadd @ execute
> ;
> 
> \ test
> const V1 1 , 2 , 3 ,
> const V2 4 , 5 , 6 ,
> 3 cells var V3
> V1 V2 V3 vadd1
> ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> 
> V1 V2 V3 vadd2
> ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> 
> : vadd
>   local{ v1 v2 v3 i }
>   v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;
> 
> : vadd3
>   local{ v1 v2 v3 }
>   v1 @ v2 @ v3 @ 0 vadd
>   v1 @ v2 @ v3 @ 1 vadd
>   v1 @ v2 @ v3 @ 2 vadd
> ;
> 
> V1 V2 V3 vadd3
> ." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> 
> result vadd1: 5 7 9
> result vadd2: 5 7 9
> result vadd3: 5 7 9
>  ok

Hi! Too much typing using locals.
One of -locals version:

: @+!  @ swap +! ;  ok              
: ++   cell+ cell under+ ;  ok      
: v+!  2dup @+! ++ 2dup @+! ++ @+! ;  ok
: v+   tuck 3 cells move swap v+! ;  ok
create A  1 , 2 , 3 ,  ok           
create B  4 , 5 , 6 ,  ok           
create C  8 , 8 , 8 ,  ok           
A B C v+ C 3 cells dump             
 BBC9420: 05 00 00 00  07 00 00 00 - 09 00 00 00               ............
 ok

Have nice day,
humptydumpty

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


#42855

Fromlehs <skydda.barnen@gmail.com>
Date2015-10-26 12:25 -0700
Message-ID<8794da96-0920-4c96-a4bf-b9ad4e623c2f@googlegroups.com>
In reply to#42848
Den måndag 26 oktober 2015 kl. 14:35:47 UTC+1 skrev humptydumpty:
> On Monday, October 26, 2015 at 2:11:01 PM UTC+2, Raimond Dragomir wrote:
> > > Why not factorize the nested function?
> > > 
> > > : th_add ( v1 v2 v3 i -- )
> > >   2>r r@ th @ swap r@ th @ + 2r> th !
> > > ;
> > > 
> > > : vadd
> > >   local{ v1 v2 v3 } 
> > >   v1 v2 v3 0 th_add 
> > >   v1 v2 v3 1 th_add
> > >   v1 v2 v3 2 th_add
> > > ; 
> > > ____________________
> > > Lars-Erik Svahn
> > > http://forthmath.blogspot.se
> > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > 
> > My vadd2 (with the quotation) is something like that.
> > I added your variant at the end, but I used only locals for the intermediate
> > vadd (your th_add):
> > 
> > : th \ base index -- value
> >   cells + ;
> > 
> > : vadd1
> >   local{ v1 v2 v3 }
> >   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
> >   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
> >   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> > ;
> > 
> > : vadd2
> >   local{ v1 v2 v3 | vadd }
> >   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
> >   0 vadd @ execute
> >   1 vadd @ execute
> >   2 vadd @ execute
> > ;
> > 
> > \ test
> > const V1 1 , 2 , 3 ,
> > const V2 4 , 5 , 6 ,
> > 3 cells var V3
> > V1 V2 V3 vadd1
> > ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > 
> > V1 V2 V3 vadd2
> > ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > 
> > : vadd
> >   local{ v1 v2 v3 i }
> >   v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;
> > 
> > : vadd3
> >   local{ v1 v2 v3 }
> >   v1 @ v2 @ v3 @ 0 vadd
> >   v1 @ v2 @ v3 @ 1 vadd
> >   v1 @ v2 @ v3 @ 2 vadd
> > ;
> > 
> > V1 V2 V3 vadd3
> > ." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > 
> > result vadd1: 5 7 9
> > result vadd2: 5 7 9
> > result vadd3: 5 7 9
> >  ok
> 
> Hi! Too much typing using locals.
> One of -locals version:
> 
> : @+!  @ swap +! ;  ok              
> : ++   cell+ cell under+ ;  ok      
> : v+!  2dup @+! ++ 2dup @+! ++ @+! ;  ok
> : v+   tuck 3 cells move swap v+! ;  ok
> create A  1 , 2 , 3 ,  ok           
> create B  4 , 5 , 6 ,  ok           
> create C  8 , 8 , 8 ,  ok           
> A B C v+ C 3 cells dump             
>  BBC9420: 05 00 00 00  07 00 00 00 - 09 00 00 00               ............
>  ok
> 
> Have nice day,
> humptydumpty

This is really nice. And it can easily be extended to more general cases.
I will adopt this - and I didn't even know there was a word like under+ ...
____________________
Lehs
http://forthmath.blogspot.se
https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

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


#42867

Fromhumptydumpty <ouatubi@gmail.com>
Date2015-10-27 00:47 -0700
Message-ID<1145aa77-b53e-42b1-84fe-4b6115e32eef@googlegroups.com>
In reply to#42855
On Monday, October 26, 2015 at 9:25:06 PM UTC+2, lehs wrote:
> Den måndag 26 oktober 2015 kl. 14:35:47 UTC+1 skrev humptydumpty:
> > On Monday, October 26, 2015 at 2:11:01 PM UTC+2, Raimond Dragomir wrote:
> > > > Why not factorize the nested function?
> > > > 
> > > > : th_add ( v1 v2 v3 i -- )
> > > >   2>r r@ th @ swap r@ th @ + 2r> th !
> > > > ;
> > > > 
> > > > : vadd
> > > >   local{ v1 v2 v3 } 
> > > >   v1 v2 v3 0 th_add 
> > > >   v1 v2 v3 1 th_add
> > > >   v1 v2 v3 2 th_add
> > > > ; 
> > > > ____________________
> > > > Lars-Erik Svahn
> > > > http://forthmath.blogspot.se
> > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > 
> > > My vadd2 (with the quotation) is something like that.
> > > I added your variant at the end, but I used only locals for the intermediate
> > > vadd (your th_add):
> > > 
> > > : th \ base index -- value
> > >   cells + ;
> > > 
> > > : vadd1
> > >   local{ v1 v2 v3 }
> > >   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
> > >   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
> > >   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> > > ;
> > > 
> > > : vadd2
> > >   local{ v1 v2 v3 | vadd }
> > >   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
> > >   0 vadd @ execute
> > >   1 vadd @ execute
> > >   2 vadd @ execute
> > > ;
> > > 
> > > \ test
> > > const V1 1 , 2 , 3 ,
> > > const V2 4 , 5 , 6 ,
> > > 3 cells var V3
> > > V1 V2 V3 vadd1
> > > ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > 
> > > V1 V2 V3 vadd2
> > > ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > 
> > > : vadd
> > >   local{ v1 v2 v3 i }
> > >   v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;
> > > 
> > > : vadd3
> > >   local{ v1 v2 v3 }
> > >   v1 @ v2 @ v3 @ 0 vadd
> > >   v1 @ v2 @ v3 @ 1 vadd
> > >   v1 @ v2 @ v3 @ 2 vadd
> > > ;
> > > 
> > > V1 V2 V3 vadd3
> > > ." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > 
> > > result vadd1: 5 7 9
> > > result vadd2: 5 7 9
> > > result vadd3: 5 7 9
> > >  ok
> > 
> > Hi! Too much typing using locals.
> > One of -locals version:
> > 
> > : @+!  @ swap +! ;  ok              
> > : ++   cell+ cell under+ ;  ok      
> > : v+!  2dup @+! ++ 2dup @+! ++ @+! ;  ok
> > : v+   tuck 3 cells move swap v+! ;  ok
> > create A  1 , 2 , 3 ,  ok           
> > create B  4 , 5 , 6 ,  ok           
> > create C  8 , 8 , 8 ,  ok           
> > A B C v+ C 3 cells dump             
> >  BBC9420: 05 00 00 00  07 00 00 00 - 09 00 00 00               ............
> >  ok
> > 
> > Have nice day,
> > humptydumpty
> 
> This is really nice. And it can easily be extended to more general cases.
> I will adopt this - and I didn't even know there was a word like under+ ...
> ____________________
> Lehs
> http://forthmath.blogspot.se
> https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

I'm glad you like it.  For me, 'v+!' word would suffice to use.

Started with 1-dimension particular case, which would use '+!'.
From using '+!' I derived stack-effect for '@+!'.  As form&function
principle - form follows the function.
Then generalized it for 3-dimension case.

Have a nice day,
humptydumpty

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


#42880

Fromlehs <skydda.barnen@gmail.com>
Date2015-10-27 08:06 -0700
Message-ID<f7ff7d24-a66d-4350-90e5-61cb8252e907@googlegroups.com>
In reply to#42867
Den tisdag 27 oktober 2015 kl. 08:47:13 UTC+1 skrev humptydumpty:
> On Monday, October 26, 2015 at 9:25:06 PM UTC+2, lehs wrote:
> > Den måndag 26 oktober 2015 kl. 14:35:47 UTC+1 skrev humptydumpty:
> > > On Monday, October 26, 2015 at 2:11:01 PM UTC+2, Raimond Dragomir wrote:
> > > > > Why not factorize the nested function?
> > > > > 
> > > > > : th_add ( v1 v2 v3 i -- )
> > > > >   2>r r@ th @ swap r@ th @ + 2r> th !
> > > > > ;
> > > > > 
> > > > > : vadd
> > > > >   local{ v1 v2 v3 } 
> > > > >   v1 v2 v3 0 th_add 
> > > > >   v1 v2 v3 1 th_add
> > > > >   v1 v2 v3 2 th_add
> > > > > ; 
> > > > > ____________________
> > > > > Lars-Erik Svahn
> > > > > http://forthmath.blogspot.se
> > > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > > 
> > > > My vadd2 (with the quotation) is something like that.
> > > > I added your variant at the end, but I used only locals for the intermediate
> > > > vadd (your th_add):
> > > > 
> > > > : th \ base index -- value
> > > >   cells + ;
> > > > 
> > > > : vadd1
> > > >   local{ v1 v2 v3 }
> > > >   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
> > > >   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
> > > >   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> > > > ;
> > > > 
> > > > : vadd2
> > > >   local{ v1 v2 v3 | vadd }
> > > >   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
> > > >   0 vadd @ execute
> > > >   1 vadd @ execute
> > > >   2 vadd @ execute
> > > > ;
> > > > 
> > > > \ test
> > > > const V1 1 , 2 , 3 ,
> > > > const V2 4 , 5 , 6 ,
> > > > 3 cells var V3
> > > > V1 V2 V3 vadd1
> > > > ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > 
> > > > V1 V2 V3 vadd2
> > > > ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > 
> > > > : vadd
> > > >   local{ v1 v2 v3 i }
> > > >   v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;
> > > > 
> > > > : vadd3
> > > >   local{ v1 v2 v3 }
> > > >   v1 @ v2 @ v3 @ 0 vadd
> > > >   v1 @ v2 @ v3 @ 1 vadd
> > > >   v1 @ v2 @ v3 @ 2 vadd
> > > > ;
> > > > 
> > > > V1 V2 V3 vadd3
> > > > ." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > 
> > > > result vadd1: 5 7 9
> > > > result vadd2: 5 7 9
> > > > result vadd3: 5 7 9
> > > >  ok
> > > 
> > > Hi! Too much typing using locals.
> > > One of -locals version:
> > > 
> > > : @+!  @ swap +! ;  ok              
> > > : ++   cell+ cell under+ ;  ok      
> > > : v+!  2dup @+! ++ 2dup @+! ++ @+! ;  ok
> > > : v+   tuck 3 cells move swap v+! ;  ok
> > > create A  1 , 2 , 3 ,  ok           
> > > create B  4 , 5 , 6 ,  ok           
> > > create C  8 , 8 , 8 ,  ok           
> > > A B C v+ C 3 cells dump             
> > >  BBC9420: 05 00 00 00  07 00 00 00 - 09 00 00 00               ............
> > >  ok
> > > 
> > > Have nice day,
> > > humptydumpty
> > 
> > This is really nice. And it can easily be extended to more general cases.
> > I will adopt this - and I didn't even know there was a word like under+ ...
> > ____________________
> > Lehs
> > http://forthmath.blogspot.se
> > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> 
> I'm glad you like it.  For me, 'v+!' word would suffice to use.
> 
> Started with 1-dimension particular case, which would use '+!'.
> From using '+!' I derived stack-effect for '@+!'.  As form&function
> principle - form follows the function.
> Then generalized it for 3-dimension case.
> 
> Have a nice day,
> humptydumpty

Your solution might be the most efficient. Ii's a bit cryptic but I think of it as an efficient low level code - this would have been machine code if the processor was well designed.

But I do understand the need of readability and my programming is often on a higher level with locals.
____________________
Lehs
http://forthmath.blogspot.se
https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

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


#42888

Fromhumptydumpty <ouatubi@gmail.com>
Date2015-10-27 23:43 -0700
Message-ID<20a59e63-0efc-4a56-9501-956338244d8d@googlegroups.com>
In reply to#42880
On Tuesday, October 27, 2015 at 5:06:44 PM UTC+2, lehs wrote:
> Den tisdag 27 oktober 2015 kl. 08:47:13 UTC+1 skrev humptydumpty:
> > On Monday, October 26, 2015 at 9:25:06 PM UTC+2, lehs wrote:
> > > Den måndag 26 oktober 2015 kl. 14:35:47 UTC+1 skrev humptydumpty:
> > > > On Monday, October 26, 2015 at 2:11:01 PM UTC+2, Raimond Dragomir wrote:
> > > > > > Why not factorize the nested function?
> > > > > > 
> > > > > > : th_add ( v1 v2 v3 i -- )
> > > > > >   2>r r@ th @ swap r@ th @ + 2r> th !
> > > > > > ;
> > > > > > 
> > > > > > : vadd
> > > > > >   local{ v1 v2 v3 } 
> > > > > >   v1 v2 v3 0 th_add 
> > > > > >   v1 v2 v3 1 th_add
> > > > > >   v1 v2 v3 2 th_add
> > > > > > ; 
> > > > > > ____________________
> > > > > > Lars-Erik Svahn
> > > > > > http://forthmath.blogspot.se
> > > > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > > > 
> > > > > My vadd2 (with the quotation) is something like that.
> > > > > I added your variant at the end, but I used only locals for the intermediate
> > > > > vadd (your th_add):
> > > > > 
> > > > > : th \ base index -- value
> > > > >   cells + ;
> > > > > 
> > > > > : vadd1
> > > > >   local{ v1 v2 v3 }
> > > > >   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
> > > > >   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
> > > > >   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> > > > > ;
> > > > > 
> > > > > : vadd2
> > > > >   local{ v1 v2 v3 | vadd }
> > > > >   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
> > > > >   0 vadd @ execute
> > > > >   1 vadd @ execute
> > > > >   2 vadd @ execute
> > > > > ;
> > > > > 
> > > > > \ test
> > > > > const V1 1 , 2 , 3 ,
> > > > > const V2 4 , 5 , 6 ,
> > > > > 3 cells var V3
> > > > > V1 V2 V3 vadd1
> > > > > ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > 
> > > > > V1 V2 V3 vadd2
> > > > > ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > 
> > > > > : vadd
> > > > >   local{ v1 v2 v3 i }
> > > > >   v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;
> > > > > 
> > > > > : vadd3
> > > > >   local{ v1 v2 v3 }
> > > > >   v1 @ v2 @ v3 @ 0 vadd
> > > > >   v1 @ v2 @ v3 @ 1 vadd
> > > > >   v1 @ v2 @ v3 @ 2 vadd
> > > > > ;
> > > > > 
> > > > > V1 V2 V3 vadd3
> > > > > ." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > 
> > > > > result vadd1: 5 7 9
> > > > > result vadd2: 5 7 9
> > > > > result vadd3: 5 7 9
> > > > >  ok
> > > > 
> > > > Hi! Too much typing using locals.
> > > > One of -locals version:
> > > > 
> > > > : @+!  @ swap +! ;  ok              
> > > > : ++   cell+ cell under+ ;  ok      
> > > > : v+!  2dup @+! ++ 2dup @+! ++ @+! ;  ok
> > > > : v+   tuck 3 cells move swap v+! ;  ok
> > > > create A  1 , 2 , 3 ,  ok           
> > > > create B  4 , 5 , 6 ,  ok           
> > > > create C  8 , 8 , 8 ,  ok           
> > > > A B C v+ C 3 cells dump             
> > > >  BBC9420: 05 00 00 00  07 00 00 00 - 09 00 00 00               ............
> > > >  ok
> > > > 
> > > > Have nice day,
> > > > humptydumpty
> > > 
> > > This is really nice. And it can easily be extended to more general cases.
> > > I will adopt this - and I didn't even know there was a word like under+ ...
> > > ____________________
> > > Lehs
> > > http://forthmath.blogspot.se
> > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > 
> > I'm glad you like it.  For me, 'v+!' word would suffice to use.
> > 
> > Started with 1-dimension particular case, which would use '+!'.
> > From using '+!' I derived stack-effect for '@+!'.  As form&function
> > principle - form follows the function.
> > Then generalized it for 3-dimension case.
> > 
> > Have a nice day,
> > humptydumpty
> 
> Your solution might be the most efficient. Ii's a bit cryptic but I think of it as an efficient low level code - this would have been machine code if the processor was well designed.
> 
> But I do understand the need of readability and my programming is often on a higher level with locals.
> ____________________
> Lehs
> http://forthmath.blogspot.se
> https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

Hi!
Use what comes handy to you. :)

A bit of charade: why on this thread everyone who wrote
only code using locals do not arrived at a solution like
extending '+!' word to something like 'v+!'? :)

Hint: only 2 posters arrived at such solution using non-locals
version.

Have a nice day,
humptydumpty

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


#42890

Fromlehs <skydda.barnen@gmail.com>
Date2015-10-28 01:30 -0700
Message-ID<ea7370ed-4c64-4c88-b491-33b72fe9efbb@googlegroups.com>
In reply to#42888
Den onsdag 28 oktober 2015 kl. 07:43:29 UTC+1 skrev humptydumpty:
> On Tuesday, October 27, 2015 at 5:06:44 PM UTC+2, lehs wrote:
> > Den tisdag 27 oktober 2015 kl. 08:47:13 UTC+1 skrev humptydumpty:
> > > On Monday, October 26, 2015 at 9:25:06 PM UTC+2, lehs wrote:
> > > > Den måndag 26 oktober 2015 kl. 14:35:47 UTC+1 skrev humptydumpty:
> > > > > On Monday, October 26, 2015 at 2:11:01 PM UTC+2, Raimond Dragomir wrote:
> > > > > > > Why not factorize the nested function?
> > > > > > > 
> > > > > > > : th_add ( v1 v2 v3 i -- )
> > > > > > >   2>r r@ th @ swap r@ th @ + 2r> th !
> > > > > > > ;
> > > > > > > 
> > > > > > > : vadd
> > > > > > >   local{ v1 v2 v3 } 
> > > > > > >   v1 v2 v3 0 th_add 
> > > > > > >   v1 v2 v3 1 th_add
> > > > > > >   v1 v2 v3 2 th_add
> > > > > > > ; 
> > > > > > > ____________________
> > > > > > > Lars-Erik Svahn
> > > > > > > http://forthmath.blogspot.se
> > > > > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > > > > 
> > > > > > My vadd2 (with the quotation) is something like that.
> > > > > > I added your variant at the end, but I used only locals for the intermediate
> > > > > > vadd (your th_add):
> > > > > > 
> > > > > > : th \ base index -- value
> > > > > >   cells + ;
> > > > > > 
> > > > > > : vadd1
> > > > > >   local{ v1 v2 v3 }
> > > > > >   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
> > > > > >   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
> > > > > >   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> > > > > > ;
> > > > > > 
> > > > > > : vadd2
> > > > > >   local{ v1 v2 v3 | vadd }
> > > > > >   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
> > > > > >   0 vadd @ execute
> > > > > >   1 vadd @ execute
> > > > > >   2 vadd @ execute
> > > > > > ;
> > > > > > 
> > > > > > \ test
> > > > > > const V1 1 , 2 , 3 ,
> > > > > > const V2 4 , 5 , 6 ,
> > > > > > 3 cells var V3
> > > > > > V1 V2 V3 vadd1
> > > > > > ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > 
> > > > > > V1 V2 V3 vadd2
> > > > > > ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > 
> > > > > > : vadd
> > > > > >   local{ v1 v2 v3 i }
> > > > > >   v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;
> > > > > > 
> > > > > > : vadd3
> > > > > >   local{ v1 v2 v3 }
> > > > > >   v1 @ v2 @ v3 @ 0 vadd
> > > > > >   v1 @ v2 @ v3 @ 1 vadd
> > > > > >   v1 @ v2 @ v3 @ 2 vadd
> > > > > > ;
> > > > > > 
> > > > > > V1 V2 V3 vadd3
> > > > > > ." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > 
> > > > > > result vadd1: 5 7 9
> > > > > > result vadd2: 5 7 9
> > > > > > result vadd3: 5 7 9
> > > > > >  ok
> > > > > 
> > > > > Hi! Too much typing using locals.
> > > > > One of -locals version:
> > > > > 
> > > > > : @+!  @ swap +! ;  ok              
> > > > > : ++   cell+ cell under+ ;  ok      
> > > > > : v+!  2dup @+! ++ 2dup @+! ++ @+! ;  ok
> > > > > : v+   tuck 3 cells move swap v+! ;  ok
> > > > > create A  1 , 2 , 3 ,  ok           
> > > > > create B  4 , 5 , 6 ,  ok           
> > > > > create C  8 , 8 , 8 ,  ok           
> > > > > A B C v+ C 3 cells dump             
> > > > >  BBC9420: 05 00 00 00  07 00 00 00 - 09 00 00 00               ............
> > > > >  ok
> > > > > 
> > > > > Have nice day,
> > > > > humptydumpty
> > > > 
> > > > This is really nice. And it can easily be extended to more general cases.
> > > > I will adopt this - and I didn't even know there was a word like under+ ...
> > > > ____________________
> > > > Lehs
> > > > http://forthmath.blogspot.se
> > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > 
> > > I'm glad you like it.  For me, 'v+!' word would suffice to use.
> > > 
> > > Started with 1-dimension particular case, which would use '+!'.
> > > From using '+!' I derived stack-effect for '@+!'.  As form&function
> > > principle - form follows the function.
> > > Then generalized it for 3-dimension case.
> > > 
> > > Have a nice day,
> > > humptydumpty
> > 
> > Your solution might be the most efficient. Ii's a bit cryptic but I think of it as an efficient low level code - this would have been machine code if the processor was well designed.
> > 
> > But I do understand the need of readability and my programming is often on a higher level with locals.
> > ____________________
> > Lehs
> > http://forthmath.blogspot.se
> > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> 
> Hi!
> Use what comes handy to you. :)
> 
> A bit of charade: why on this thread everyone who wrote
> only code using locals do not arrived at a solution like
> extending '+!' word to something like 'v+!'? :)
> 
> Hint: only 2 posters arrived at such solution using non-locals
> version.
> 
> Have a nice day,
> humptydumpty
If you suggest that there is an inherent logic/style in Forth and that locals is a pollution, I'm prepared to aggre. Even if we have to program in our own style it might be a good idea to practice clean-Forth-style coding now and then. I will think about your ideas of function, style and generalization and see what it will lead me to.

____________________
Lehs
http://forthmath.blogspot.se/
https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

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


#42891

Fromhumptydumpty <ouatubi@gmail.com>
Date2015-10-28 01:58 -0700
Message-ID<1212252a-f8bf-4ec0-a095-72d79bd73c39@googlegroups.com>
In reply to#42890
miercuri, 28 octombrie 2015, 10:30:09 UTC+2, lehs a scris:
> Den onsdag 28 oktober 2015 kl. 07:43:29 UTC+1 skrev humptydumpty:
> > On Tuesday, October 27, 2015 at 5:06:44 PM UTC+2, lehs wrote:
> > > Den tisdag 27 oktober 2015 kl. 08:47:13 UTC+1 skrev humptydumpty:
> > > > On Monday, October 26, 2015 at 9:25:06 PM UTC+2, lehs wrote:
> > > > > Den måndag 26 oktober 2015 kl. 14:35:47 UTC+1 skrev humptydumpty:
> > > > > > On Monday, October 26, 2015 at 2:11:01 PM UTC+2, Raimond Dragomir wrote:
> > > > > > > > Why not factorize the nested function?
> > > > > > > > 
> > > > > > > > : th_add ( v1 v2 v3 i -- )
> > > > > > > >   2>r r@ th @ swap r@ th @ + 2r> th !
> > > > > > > > ;
> > > > > > > > 
> > > > > > > > : vadd
> > > > > > > >   local{ v1 v2 v3 } 
> > > > > > > >   v1 v2 v3 0 th_add 
> > > > > > > >   v1 v2 v3 1 th_add
> > > > > > > >   v1 v2 v3 2 th_add
> > > > > > > > ; 
> > > > > > > > ____________________
> > > > > > > > Lars-Erik Svahn
> > > > > > > > http://forthmath.blogspot.se
> > > > > > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > > > > > 
> > > > > > > My vadd2 (with the quotation) is something like that.
> > > > > > > I added your variant at the end, but I used only locals for the intermediate
> > > > > > > vadd (your th_add):
> > > > > > > 
> > > > > > > : th \ base index -- value
> > > > > > >   cells + ;
> > > > > > > 
> > > > > > > : vadd1
> > > > > > >   local{ v1 v2 v3 }
> > > > > > >   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
> > > > > > >   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
> > > > > > >   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> > > > > > > ;
> > > > > > > 
> > > > > > > : vadd2
> > > > > > >   local{ v1 v2 v3 | vadd }
> > > > > > >   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
> > > > > > >   0 vadd @ execute
> > > > > > >   1 vadd @ execute
> > > > > > >   2 vadd @ execute
> > > > > > > ;
> > > > > > > 
> > > > > > > \ test
> > > > > > > const V1 1 , 2 , 3 ,
> > > > > > > const V2 4 , 5 , 6 ,
> > > > > > > 3 cells var V3
> > > > > > > V1 V2 V3 vadd1
> > > > > > > ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > > 
> > > > > > > V1 V2 V3 vadd2
> > > > > > > ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > > 
> > > > > > > : vadd
> > > > > > >   local{ v1 v2 v3 i }
> > > > > > >   v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;
> > > > > > > 
> > > > > > > : vadd3
> > > > > > >   local{ v1 v2 v3 }
> > > > > > >   v1 @ v2 @ v3 @ 0 vadd
> > > > > > >   v1 @ v2 @ v3 @ 1 vadd
> > > > > > >   v1 @ v2 @ v3 @ 2 vadd
> > > > > > > ;
> > > > > > > 
> > > > > > > V1 V2 V3 vadd3
> > > > > > > ." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > > 
> > > > > > > result vadd1: 5 7 9
> > > > > > > result vadd2: 5 7 9
> > > > > > > result vadd3: 5 7 9
> > > > > > >  ok
> > > > > > 
> > > > > > Hi! Too much typing using locals.
> > > > > > One of -locals version:
> > > > > > 
> > > > > > : @+!  @ swap +! ;  ok              
> > > > > > : ++   cell+ cell under+ ;  ok      
> > > > > > : v+!  2dup @+! ++ 2dup @+! ++ @+! ;  ok
> > > > > > : v+   tuck 3 cells move swap v+! ;  ok
> > > > > > create A  1 , 2 , 3 ,  ok           
> > > > > > create B  4 , 5 , 6 ,  ok           
> > > > > > create C  8 , 8 , 8 ,  ok           
> > > > > > A B C v+ C 3 cells dump             
> > > > > >  BBC9420: 05 00 00 00  07 00 00 00 - 09 00 00 00               ............
> > > > > >  ok
> > > > > > 
> > > > > > Have nice day,
> > > > > > humptydumpty
> > > > > 
> > > > > This is really nice. And it can easily be extended to more general cases.
> > > > > I will adopt this - and I didn't even know there was a word like under+ ...
> > > > > ____________________
> > > > > Lehs
> > > > > http://forthmath.blogspot.se
> > > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > > 
> > > > I'm glad you like it.  For me, 'v+!' word would suffice to use.
> > > > 
> > > > Started with 1-dimension particular case, which would use '+!'.
> > > > From using '+!' I derived stack-effect for '@+!'.  As form&function
> > > > principle - form follows the function.
> > > > Then generalized it for 3-dimension case.
> > > > 
> > > > Have a nice day,
> > > > humptydumpty
> > > 
> > > Your solution might be the most efficient. Ii's a bit cryptic but I think of it as an efficient low level code - this would have been machine code if the processor was well designed.
> > > 
> > > But I do understand the need of readability and my programming is often on a higher level with locals.
> > > ____________________
> > > Lehs
> > > http://forthmath.blogspot.se
> > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > 
> > Hi!
> > Use what comes handy to you. :)
> > 
> > A bit of charade: why on this thread everyone who wrote
> > only code using locals do not arrived at a solution like
> > extending '+!' word to something like 'v+!'? :)
> > 
> > Hint: only 2 posters arrived at such solution using non-locals
> > version.
> > 
> > Have a nice day,
> > humptydumpty
> If you suggest that there is an inherent logic/style in Forth and that locals is a pollution, I'm prepared to aggre. Even if we have to program in our own style it might be a good idea to practice clean-Forth-style coding now and then. I will think about your ideas of function, style and generalization and see what it will lead me to.
> 
> ____________________
> Lehs
> http://forthmath.blogspot.se/
> https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

I suppose that is an inherent logic/style in Forth.  I don't think locals is
 a pollution, but an easy-way.  If I give to early into easy-way then I
could overlook some opportunities for better.

Have a nice day,
humptydumpty

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


#42894

Fromfranck.bensusan@gmail.com
Date2015-10-28 02:56 -0700
Message-ID<c819767f-cc4b-4b21-97bc-a2edc842ca18@googlegroups.com>
In reply to#42891
Le mercredi 28 octobre 2015 09:58:25 UTC+1, humptydumpty a écrit :
> miercuri, 28 octombrie 2015, 10:30:09 UTC+2, lehs a scris:
> > Den onsdag 28 oktober 2015 kl. 07:43:29 UTC+1 skrev humptydumpty:
> > > On Tuesday, October 27, 2015 at 5:06:44 PM UTC+2, lehs wrote:
> > > > Den tisdag 27 oktober 2015 kl. 08:47:13 UTC+1 skrev humptydumpty:
> > > > > On Monday, October 26, 2015 at 9:25:06 PM UTC+2, lehs wrote:
> > > > > > Den måndag 26 oktober 2015 kl. 14:35:47 UTC+1 skrev humptydumpty:
> > > > > > > On Monday, October 26, 2015 at 2:11:01 PM UTC+2, Raimond Dragomir wrote:
> > > > > > > > > Why not factorize the nested function?
> > > > > > > > > 
> > > > > > > > > : th_add ( v1 v2 v3 i -- )
> > > > > > > > >   2>r r@ th @ swap r@ th @ + 2r> th !
> > > > > > > > > ;
> > > > > > > > > 
> > > > > > > > > : vadd
> > > > > > > > >   local{ v1 v2 v3 } 
> > > > > > > > >   v1 v2 v3 0 th_add 
> > > > > > > > >   v1 v2 v3 1 th_add
> > > > > > > > >   v1 v2 v3 2 th_add
> > > > > > > > > ; 
> > > > > > > > > ____________________
> > > > > > > > > Lars-Erik Svahn
> > > > > > > > > http://forthmath.blogspot.se
> > > > > > > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > > > > > > 
> > > > > > > > My vadd2 (with the quotation) is something like that.
> > > > > > > > I added your variant at the end, but I used only locals for the intermediate
> > > > > > > > vadd (your th_add):
> > > > > > > > 
> > > > > > > > : th \ base index -- value
> > > > > > > >   cells + ;
> > > > > > > > 
> > > > > > > > : vadd1
> > > > > > > >   local{ v1 v2 v3 }
> > > > > > > >   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
> > > > > > > >   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
> > > > > > > >   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> > > > > > > > ;
> > > > > > > > 
> > > > > > > > : vadd2
> > > > > > > >   local{ v1 v2 v3 | vadd }
> > > > > > > >   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
> > > > > > > >   0 vadd @ execute
> > > > > > > >   1 vadd @ execute
> > > > > > > >   2 vadd @ execute
> > > > > > > > ;
> > > > > > > > 
> > > > > > > > \ test
> > > > > > > > const V1 1 , 2 , 3 ,
> > > > > > > > const V2 4 , 5 , 6 ,
> > > > > > > > 3 cells var V3
> > > > > > > > V1 V2 V3 vadd1
> > > > > > > > ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > > > 
> > > > > > > > V1 V2 V3 vadd2
> > > > > > > > ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > > > 
> > > > > > > > : vadd
> > > > > > > >   local{ v1 v2 v3 i }
> > > > > > > >   v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;
> > > > > > > > 
> > > > > > > > : vadd3
> > > > > > > >   local{ v1 v2 v3 }
> > > > > > > >   v1 @ v2 @ v3 @ 0 vadd
> > > > > > > >   v1 @ v2 @ v3 @ 1 vadd
> > > > > > > >   v1 @ v2 @ v3 @ 2 vadd
> > > > > > > > ;
> > > > > > > > 
> > > > > > > > V1 V2 V3 vadd3
> > > > > > > > ." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > > > 
> > > > > > > > result vadd1: 5 7 9
> > > > > > > > result vadd2: 5 7 9
> > > > > > > > result vadd3: 5 7 9
> > > > > > > >  ok
> > > > > > > 
> > > > > > > Hi! Too much typing using locals.
> > > > > > > One of -locals version:
> > > > > > > 
> > > > > > > : @+!  @ swap +! ;  ok              
> > > > > > > : ++   cell+ cell under+ ;  ok      
> > > > > > > : v+!  2dup @+! ++ 2dup @+! ++ @+! ;  ok
> > > > > > > : v+   tuck 3 cells move swap v+! ;  ok
> > > > > > > create A  1 , 2 , 3 ,  ok           
> > > > > > > create B  4 , 5 , 6 ,  ok           
> > > > > > > create C  8 , 8 , 8 ,  ok           
> > > > > > > A B C v+ C 3 cells dump             
> > > > > > >  BBC9420: 05 00 00 00  07 00 00 00 - 09 00 00 00               ............
> > > > > > >  ok
> > > > > > > 
> > > > > > > Have nice day,
> > > > > > > humptydumpty
> > > > > > 
> > > > > > This is really nice. And it can easily be extended to more general cases.
> > > > > > I will adopt this - and I didn't even know there was a word like under+ ...
> > > > > > ____________________
> > > > > > Lehs
> > > > > > http://forthmath.blogspot.se
> > > > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > > > 
> > > > > I'm glad you like it.  For me, 'v+!' word would suffice to use.
> > > > > 
> > > > > Started with 1-dimension particular case, which would use '+!'.
> > > > > From using '+!' I derived stack-effect for '@+!'.  As form&function
> > > > > principle - form follows the function.
> > > > > Then generalized it for 3-dimension case.
> > > > > 
> > > > > Have a nice day,
> > > > > humptydumpty
> > > > 
> > > > Your solution might be the most efficient. Ii's a bit cryptic but I think of it as an efficient low level code - this would have been machine code if the processor was well designed.
> > > > 
> > > > But I do understand the need of readability and my programming is often on a higher level with locals.
> > > > ____________________
> > > > Lehs
> > > > http://forthmath.blogspot.se
> > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > 
> > > Hi!
> > > Use what comes handy to you. :)
> > > 
> > > A bit of charade: why on this thread everyone who wrote
> > > only code using locals do not arrived at a solution like
> > > extending '+!' word to something like 'v+!'? :)
> > > 
> > > Hint: only 2 posters arrived at such solution using non-locals
> > > version.
> > > 
> > > Have a nice day,
> > > humptydumpty
> > If you suggest that there is an inherent logic/style in Forth and that locals is a pollution, I'm prepared to aggre. Even if we have to program in our own style it might be a good idea to practice clean-Forth-style coding now and then. I will think about your ideas of function, style and generalization and see what it will lead me to.
> > 
> > ____________________
> > Lehs
> > http://forthmath.blogspot.se/
> > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> 
> I suppose that is an inherent logic/style in Forth.  I don't think locals is
>  a pollution, but an easy-way.  If I give to early into easy-way then I
> could overlook some opportunities for better.
> 
> Have a nice day,
> humptydumpty

Hi,

For me, I just think about locals as a better tool than 
>R, R>, R@, ... words. 

Perhap's I'am wrong, but I don't use those words anymore. 
This is, for me, the exact point when I switch to a local.

I agree with you about giving to early into easy-way. I just think 
that giving to early into locals is the same as giving too early
into R>, >R, ...

Regards,
Franck

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


#42897

Fromlehs <skydda.barnen@gmail.com>
Date2015-10-28 03:36 -0700
Message-ID<e5884e63-bab1-4db9-8b56-13dd03dbfec3@googlegroups.com>
In reply to#42891
Den onsdag 28 oktober 2015 kl. 09:58:25 UTC+1 skrev humptydumpty:
> miercuri, 28 octombrie 2015, 10:30:09 UTC+2, lehs a scris:
> > Den onsdag 28 oktober 2015 kl. 07:43:29 UTC+1 skrev humptydumpty:
> > > On Tuesday, October 27, 2015 at 5:06:44 PM UTC+2, lehs wrote:
> > > > Den tisdag 27 oktober 2015 kl. 08:47:13 UTC+1 skrev humptydumpty:
> > > > > On Monday, October 26, 2015 at 9:25:06 PM UTC+2, lehs wrote:
> > > > > > Den måndag 26 oktober 2015 kl. 14:35:47 UTC+1 skrev humptydumpty:
> > > > > > > On Monday, October 26, 2015 at 2:11:01 PM UTC+2, Raimond Dragomir wrote:
> > > > > > > > > Why not factorize the nested function?
> > > > > > > > > 
> > > > > > > > > : th_add ( v1 v2 v3 i -- )
> > > > > > > > >   2>r r@ th @ swap r@ th @ + 2r> th !
> > > > > > > > > ;
> > > > > > > > > 
> > > > > > > > > : vadd
> > > > > > > > >   local{ v1 v2 v3 } 
> > > > > > > > >   v1 v2 v3 0 th_add 
> > > > > > > > >   v1 v2 v3 1 th_add
> > > > > > > > >   v1 v2 v3 2 th_add
> > > > > > > > > ; 
> > > > > > > > > ____________________
> > > > > > > > > Lars-Erik Svahn
> > > > > > > > > http://forthmath.blogspot.se
> > > > > > > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > > > > > > 
> > > > > > > > My vadd2 (with the quotation) is something like that.
> > > > > > > > I added your variant at the end, but I used only locals for the intermediate
> > > > > > > > vadd (your th_add):
> > > > > > > > 
> > > > > > > > : th \ base index -- value
> > > > > > > >   cells + ;
> > > > > > > > 
> > > > > > > > : vadd1
> > > > > > > >   local{ v1 v2 v3 }
> > > > > > > >   v1 @ 0 th @  v2 @ 0 th @ +  v3 @ 0 th !
> > > > > > > >   v1 @ 1 th @  v2 @ 1 th @ +  v3 @ 1 th !
> > > > > > > >   v1 @ 2 th @  v2 @ 2 th @ +  v3 @ 2 th !
> > > > > > > > ;
> > > > > > > > 
> > > > > > > > : vadd2
> > > > > > > >   local{ v1 v2 v3 | vadd }
> > > > > > > >   { >r v1 @ r@ th @  v2 @ r@ th @ +  v3 @ r> th ! } vadd !
> > > > > > > >   0 vadd @ execute
> > > > > > > >   1 vadd @ execute
> > > > > > > >   2 vadd @ execute
> > > > > > > > ;
> > > > > > > > 
> > > > > > > > \ test
> > > > > > > > const V1 1 , 2 , 3 ,
> > > > > > > > const V2 4 , 5 , 6 ,
> > > > > > > > 3 cells var V3
> > > > > > > > V1 V2 V3 vadd1
> > > > > > > > ." result vadd1: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > > > 
> > > > > > > > V1 V2 V3 vadd2
> > > > > > > > ." result vadd2: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > > > 
> > > > > > > > : vadd
> > > > > > > >   local{ v1 v2 v3 i }
> > > > > > > >   v1 @ i @ th @  v2 @ i @ th @ +  v3 @ i @ th ! ;
> > > > > > > > 
> > > > > > > > : vadd3
> > > > > > > >   local{ v1 v2 v3 }
> > > > > > > >   v1 @ v2 @ v3 @ 0 vadd
> > > > > > > >   v1 @ v2 @ v3 @ 1 vadd
> > > > > > > >   v1 @ v2 @ v3 @ 2 vadd
> > > > > > > > ;
> > > > > > > > 
> > > > > > > > V1 V2 V3 vadd3
> > > > > > > > ." result vadd3: " V3 0 th @ . V3 1 th @ . V3 2 th @ . cr
> > > > > > > > 
> > > > > > > > result vadd1: 5 7 9
> > > > > > > > result vadd2: 5 7 9
> > > > > > > > result vadd3: 5 7 9
> > > > > > > >  ok
> > > > > > > 
> > > > > > > Hi! Too much typing using locals.
> > > > > > > One of -locals version:
> > > > > > > 
> > > > > > > : @+!  @ swap +! ;  ok              
> > > > > > > : ++   cell+ cell under+ ;  ok      
> > > > > > > : v+!  2dup @+! ++ 2dup @+! ++ @+! ;  ok
> > > > > > > : v+   tuck 3 cells move swap v+! ;  ok
> > > > > > > create A  1 , 2 , 3 ,  ok           
> > > > > > > create B  4 , 5 , 6 ,  ok           
> > > > > > > create C  8 , 8 , 8 ,  ok           
> > > > > > > A B C v+ C 3 cells dump             
> > > > > > >  BBC9420: 05 00 00 00  07 00 00 00 - 09 00 00 00               ............
> > > > > > >  ok
> > > > > > > 
> > > > > > > Have nice day,
> > > > > > > humptydumpty
> > > > > > 
> > > > > > This is really nice. And it can easily be extended to more general cases.
> > > > > > I will adopt this - and I didn't even know there was a word like under+ ...
> > > > > > ____________________
> > > > > > Lehs
> > > > > > http://forthmath.blogspot.se
> > > > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > > > 
> > > > > I'm glad you like it.  For me, 'v+!' word would suffice to use.
> > > > > 
> > > > > Started with 1-dimension particular case, which would use '+!'.
> > > > > From using '+!' I derived stack-effect for '@+!'.  As form&function
> > > > > principle - form follows the function.
> > > > > Then generalized it for 3-dimension case.
> > > > > 
> > > > > Have a nice day,
> > > > > humptydumpty
> > > > 
> > > > Your solution might be the most efficient. Ii's a bit cryptic but I think of it as an efficient low level code - this would have been machine code if the processor was well designed.
> > > > 
> > > > But I do understand the need of readability and my programming is often on a higher level with locals.
> > > > ____________________
> > > > Lehs
> > > > http://forthmath.blogspot.se
> > > > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> > > 
> > > Hi!
> > > Use what comes handy to you. :)
> > > 
> > > A bit of charade: why on this thread everyone who wrote
> > > only code using locals do not arrived at a solution like
> > > extending '+!' word to something like 'v+!'? :)
> > > 
> > > Hint: only 2 posters arrived at such solution using non-locals
> > > version.
> > > 
> > > Have a nice day,
> > > humptydumpty
> > If you suggest that there is an inherent logic/style in Forth and that locals is a pollution, I'm prepared to aggre. Even if we have to program in our own style it might be a good idea to practice clean-Forth-style coding now and then. I will think about your ideas of function, style and generalization and see what it will lead me to.
> > 
> > ____________________
> > Lehs
> > http://forthmath.blogspot.se/
> > https://github.com/Lehs/BIG-INTEGER-ANS-FORTH
> 
> I suppose that is an inherent logic/style in Forth.  I don't think locals is
>  a pollution, but an easy-way.  If I give to early into easy-way then I
> could overlook some opportunities for better.
> 
> Have a nice day,
> humptydumpty

No, I don't mean that locals is pollution in Forth, but a pollution that disturb the process of Forth style learning. To make code more easy to read on a higher level, locals is a good idea.

I will think about your pedagogical challenge.
____________________
Lehs
http://forthmath.blogspot.se
https://github.com/Lehs/BIG-INTEGER-ANS-FORTH

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


#42900

FromHans Bezemer <the.beez.speaks@gmail.com>
Date2015-10-28 15:31 +0100
Message-ID<5630dbdc$0$23812$e4fe514c@news.xs4all.nl>
In reply to#42888
humptydumpty wrote:
> A bit of charade: why on this thread everyone who wrote
> only code using locals do not arrived at a solution like
> extending '+!' word to something like 'v+!'? :)
> 
> Hint: only 2 posters arrived at such solution using non-locals
> version.
Good thinking! PLACE / +PLACE like!!

: []+! 0 ?do over i th @ over i th +! loop nip ;
: []! 0 ?do over i th @ over i th ! loop nip ;
: v! dup >r []! r> []+! drop ; : v3! 3 v! ;

Hans Bezemer

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


#42863

FromPaul Rubin <no.email@nospam.invalid>
Date2015-10-26 21:58 -0700
Message-ID<87y4eovrf6.fsf@jester.gateway.sonic.net>
In reply to#42831
Raimond Dragomir <raimond.dragomir@gmail.com> writes:
> Why would you need a nested function for such a trivial problem?

Of course it's not needed-- it just allows a little more factoring,
which can be nice depending on your tastes.

> : vadd2
>   local{ v1 v2 v3 | vadd }
>   { >r v1 @ r@ th @  v2 @ r@ th @  v3 @ r> th ! } vadd !
>   0 vadd @ execute
>   1 vadd @ execute
>   2 vadd @ execute
> ;

That is nice.  Note that there was a big discussion a few months ago
about whether the Forth 200x standard's quotations should allow
accessing the parent's locals like that, and I think the result was that
it was considered to potentially complicate implementations too much to
be worthwhile.  If you've got a simple implementation you might want to
comment.

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


#42864

FromRaimond Dragomir <raimond.dragomir@gmail.com>
Date2015-10-26 23:38 -0700
Message-ID<7e2ab23e-736d-4de9-a7ea-02656076c01f@googlegroups.com>
In reply to#42863
marți, 27 octombrie 2015, 06:58:23 UTC+2, Paul Rubin a scris:
> Raimond Dragomir <raimond.dragomir@gmail.com> writes:
> > Why would you need a nested function for such a trivial problem?
> 
> Of course it's not needed-- it just allows a little more factoring,
> which can be nice depending on your tastes.
> 
> > : vadd2
> >   local{ v1 v2 v3 | vadd }
> >   { >r v1 @ r@ th @  v2 @ r@ th @  v3 @ r> th ! } vadd !
> >   0 vadd @ execute
> >   1 vadd @ execute
> >   2 vadd @ execute
> > ;
> 
> That is nice.  Note that there was a big discussion a few months ago
> about whether the Forth 200x standard's quotations should allow
> accessing the parent's locals like that, and I think the result was that
> it was considered to potentially complicate implementations too much to
> be worthwhile.  If you've got a simple implementation you might want to
> comment.

You would be surprised how simple is the implementation. But I would not
comment more because it's clear that even locals are not welcome here...
Not to say about quotations... I will not start it again.

For me, about all examples given here without locals are just criptic things,
hard to read and understand. They really need the original C source as the
comment, and even with the C source side by side it's hard to read the forth
code...

One thing I want to comment. If you noticed, my locals are like global
variables, they need @ and !. When you have a lot of locals like in these
examples, it seems that the @'s are too many... This is indeed a drawback.
On the other hand, the overall system is less confusing (all variables,
global, local, are at the same "type") and besides that, there is a real 
technical merit: you can have words that work on variables (pointers) that
will work on both global and local variables. This helps having "library"
words. Let's take a very simple example: supose you're tired of doing "@ execute" all the time. You then can make:
: vexec @ execute ;
Now, you can use vexec on global variables AND locals:
: vadd2
  local{ v1 v2 v3 | vadd }
  { >r v1 @ r@ th @  v2 @ r@ th @  v3 @ r> th ! } vadd !
  0 vadd vexec
  1 vadd vexec
  2 vadd vexec
  ;

Or, if you want to have "friends" of +! (for example, I always need to set
and clear bits in memory so I have AND! and OR!) they will work again, on 
both local and global variables:

: or! \ x adr --
  dup >r @ or r> ! ;

: and! \ x adr --
  dup >r @ and r> ! ;

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web