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


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

How do you remember the stack?

Started bylaheadle@gmail.com
First post2016-02-12 13:57 -0800
Last post2016-02-22 01:46 -0800
Articles 20 on this page of 115 — 26 participants

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


Contents

  How do you remember the stack? laheadle@gmail.com - 2016-02-12 13:57 -0800
    Re: How do you remember the stack? Paul Rubin <no.email@nospam.invalid> - 2016-02-12 14:08 -0800
      Re: How do you remember the stack? "HAA" <someone@microsoft.com> - 2016-02-16 13:35 +1100
        Re: How do you remember the stack? Julian Fondren <julian.fondren@gmail.com> - 2016-02-15 19:28 -0800
        Re: How do you remember the stack? Whammo <sidciavic@gmail.com> - 2016-02-15 19:54 -0800
        Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-16 07:28 +0000
          Re: How do you remember the stack? "Elizabeth D. Rather" <erather@forth.com> - 2016-02-15 22:03 -1000
            Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-16 13:30 +0000
              Re: How do you remember the stack? "Elizabeth D. Rather" <erather@forth.com> - 2016-02-16 08:20 -1000
                Re: How do you remember the stack? dunno <dunno@dunno.dunno> - 2016-02-16 20:48 +0000
                Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-17 15:42 +0000
            Re: How do you remember the stack? "HAA" <someone@microsoft.com> - 2016-02-18 18:48 +1100
              Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-02-18 12:27 -0800
                Re: How do you remember the stack? Julian Fondren <julian.fondren@gmail.com> - 2016-02-18 14:53 -0800
                  Re: How do you remember the stack? Julian Fondren <julian.fondren@gmail.com> - 2016-02-18 15:18 -0800
                Re: How do you remember the stack? "HAA" <someone@microsoft.com> - 2016-02-21 13:32 +1100
                  Re: How do you remember the stack? Chris Curl <ccurl609@gmail.com> - 2016-02-20 20:57 -0800
                    Re: How do you remember the stack? Ron Aaron <rambamist@gmail.com> - 2016-02-21 07:23 +0200
                      Re: How do you remember the stack? Chris Curl <ccurl609@gmail.com> - 2016-02-21 08:54 -0800
                  Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-02-21 22:05 -0800
                  Re: How do you remember the stack? Lars Brinkhoff <lars.spam@nocrew.org> - 2016-02-22 16:20 +0100
                    Re: How do you remember the stack? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-02-22 09:47 -0600
                    Re: How do you remember the stack? Whammo <sidciavic@gmail.com> - 2016-02-23 16:51 -0800
                      Re: How do you remember the stack? "HAA" <someone@microsoft.com> - 2016-02-28 15:22 +1100
                        Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-02-27 21:30 -0800
                          Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-02-27 21:33 -0800
                        Re: How do you remember the stack? "Elizabeth D. Rather" <erather@forth.com> - 2016-02-27 21:39 -1000
                          Re: How do you remember the stack? "HAA" <someone@microsoft.com> - 2016-02-29 13:47 +1100
                            Re: How do you remember the stack? Paul Rubin <no.email@nospam.invalid> - 2016-02-28 19:02 -0800
                              Re: How do you remember the stack? Julian Fondren <julian.fondren@gmail.com> - 2016-02-28 22:26 -0800
                                Re: How do you remember the stack? Paul Rubin <no.email@nospam.invalid> - 2016-02-28 22:37 -0800
                            Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-02-28 19:11 -0800
                            Re: How do you remember the stack? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-02-29 11:55 -0600
                            Re: How do you remember the stack? "Elizabeth D. Rather" <erather@forth.com> - 2016-02-29 19:30 -1000
                              Re: How do you remember the stack? "HAA" <someone@microsoft.com> - 2016-03-02 00:49 +1100
                                Re: How do you remember the stack? "Elizabeth D. Rather" <erather@forth.com> - 2016-03-01 13:50 -1000
                                Re: How do you remember the stack? Paul Rubin <no.email@nospam.invalid> - 2016-03-01 16:49 -0800
                                  Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-03-01 18:04 -0800
                                  Re: How do you remember the stack? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-03-02 02:53 -0600
                                  Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-03-02 09:57 +0000
                                    Re: How do you remember the stack? Pablo Hugo Reda <pabloreda@gmail.com> - 2016-03-02 03:21 -0800
                                      Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-03-02 11:49 +0000
                                        Re: How do you remember the stack? Pablo Hugo Reda <pabloreda@gmail.com> - 2016-03-02 04:23 -0800
                                    Re: How do you remember the stack? stephen@mpeforth.com (Stephen Pelc) - 2016-03-02 18:32 +0000
                                      Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-03-02 18:41 +0000
                                        Re: How do you remember the stack? stephen@mpeforth.com (Stephen Pelc) - 2016-03-02 20:36 +0000
                                        Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-03-03 07:38 +0000
                                          Re: How do you remember the stack? stephen@mpeforth.com (Stephen Pelc) - 2016-03-03 09:26 +0000
                                            Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-03-03 11:15 +0000
                                              Re: How do you remember the stack? stephen@mpeforth.com (Stephen Pelc) - 2016-03-03 15:35 +0000
                                                Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-03-03 15:56 +0000
                                                  Re: How do you remember the stack? stephen@mpeforth.com (Stephen Pelc) - 2016-03-03 17:04 +0000
                                Re: How do you remember the stack? Whammo <sidciavic@gmail.com> - 2016-03-01 19:29 -0800
                        Re: How do you remember the stack? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-28 18:52 +0000
                        Re: How do you remember the stack? Whammo <sidciavic@gmail.com> - 2016-02-28 13:30 -0800
                        Re: How do you remember the stack? Lars Brinkhoff <lars.spam@nocrew.org> - 2016-02-29 07:55 +0100
                          Re: How do you remember the stack? "Elizabeth D. Rather" <erather@forth.com> - 2016-02-29 19:34 -1000
                            Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-03-01 20:40 -0800
                            Re: How do you remember the stack? Unknown <dog@gmail.com> - 2016-06-02 05:46 +0000
                              Re: How do you remember the stack? Lars Brinkhoff <lars.spam@nocrew.org> - 2016-06-02 08:48 +0200
                                Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-06-02 00:17 -0700
                                Re: How do you remember the stack? Michael Barry <barrym95838@yahoo.com> - 2016-06-02 19:48 -0700
                                  Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-06-02 20:34 -0700
                  Re: How do you remember the stack? "WJ" <w_a_x_man@yahoo.com> - 2016-02-22 19:23 +0000
                    Re: How do you remember the stack? "HAA" <someone@microsoft.com> - 2016-02-25 20:31 +1100
                      Re: How do you remember the stack? Julian Fondren <julian.fondren@gmail.com> - 2016-02-25 07:44 -0800
                        Re: How do you remember the stack? Lars Brinkhoff <lars.spam@nocrew.org> - 2016-02-25 20:22 +0100
                        Re: How do you remember the stack? "HAA" <someone@microsoft.com> - 2016-02-28 13:43 +1100
                          Re: How do you remember the stack? "Elizabeth D. Rather" <erather@forth.com> - 2016-02-27 21:43 -1000
                            Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-28 14:53 +0000
                            Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-02-28 15:27 -0800
                  Re: How do you remember the stack? humptydumpty <ouatubi@gmail.com> - 2016-06-02 02:02 -0700
                  Re: How do you remember the stack? JennyB <jennybrien@googlemail.com> - 2016-06-03 05:57 -0700
        Re: How do you remember the stack? Bernd Paysan <bernd.paysan@gmx.de> - 2016-03-01 16:38 +0000
    Re: How do you remember the stack? Chris Curl <ccurl609@gmail.com> - 2016-02-12 16:31 -0800
    Re: How do you remember the stack? Whammo <sidciavic@gmail.com> - 2016-02-12 17:31 -0800
    Re: How do you remember the stack? Lars Brinkhoff <lars.spam@nocrew.org> - 2016-02-13 08:03 +0100
    Re: How do you remember the stack? dunno <dunno@dunno.dunno> - 2016-02-13 08:06 +0000
      Re: How do you remember the stack? minforth@arcor.de - 2016-02-13 01:50 -0800
        Re: How do you remember the stack? mhx@iae.nl - 2016-02-13 03:22 -0800
          Re: How do you remember the stack? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-13 17:09 +0000
        Re: How do you remember the stack? mhx@iae.nl - 2016-02-13 03:39 -0800
        Re: How do you remember the stack? mhx@iae.nl - 2016-02-13 03:42 -0800
        Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-13 11:27 +0000
          Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-13 12:33 +0000
            Re: How do you remember the stack? minforth@arcor.de - 2016-02-15 01:05 -0800
        Re: How do you remember the stack? dunno <dunno@dunno.dunno> - 2016-02-14 19:34 +0000
    Re: How do you remember the stack? Julian Fondren <julian.fondren@gmail.com> - 2016-02-13 06:43 -0800
      Re: How do you remember the stack? minforth@arcor.de - 2016-02-15 01:22 -0800
        Re: How do you remember the stack? dunno <dunno@dunno.dunno> - 2016-02-15 09:48 +0000
        Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-15 09:53 +0000
          Re: How do you remember the stack? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-15 11:26 +0000
            Re: How do you remember the stack? minforth@arcor.de - 2016-02-15 04:53 -0800
              Re: How do you remember the stack? dunno <dunno@dunno.dunno> - 2016-02-15 17:06 +0000
                Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-16 14:57 +0000
            Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-16 14:14 +0000
        Re: How do you remember the stack? Ron Aaron <rambamist@gmail.com> - 2016-02-15 12:31 +0200
        Re: How do you remember the stack? Jan Coombs <jenfhaomndgfwutc@murmic.plus.com> - 2016-02-18 22:53 +0000
    Re: How do you remember the stack? Doug Hoffman <glidedog@gmail.com> - 2016-02-13 10:51 -0500
    Re: How do you remember the stack? "HAA" <someone@microsoft.com> - 2016-02-14 10:18 +1100
    Re: How do you remember the stack? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-02-14 04:21 -0600
    Re: How do you remember the stack? Whammo <sidciavic@gmail.com> - 2016-02-20 14:36 -0800
      Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-21 16:35 +0000
        Re: How do you remember the stack? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-21 18:34 +0000
          Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-22 09:52 +0000
            Re: How do you remember the stack? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-22 13:07 +0000
              Re: How do you remember the stack? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-22 15:41 +0000
                Re: How do you remember the stack? "Elizabeth D. Rather" <erather@forth.com> - 2016-02-22 08:24 -1000
              Re: How do you remember the stack? "Elizabeth D. Rather" <erather@forth.com> - 2016-02-22 08:21 -1000
                Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-02-22 17:51 -0800
                  Re: How do you remember the stack? hughaguilar96@gmail.com - 2016-02-22 18:15 -0800
                  Re: How do you remember the stack? "WJ" <w_a_x_man@yahoo.com> - 2016-02-29 06:20 +0000
                  Re: How do you remember the stack? "WJ" <w_a_x_man@yahoo.com> - 2016-03-02 20:42 +0000
                    Re: How do you remember the stack? "WJ" <w_a_x_man@yahoo.com> - 2016-06-02 20:13 +0000
    Re: How do you remember the stack? humptydumpty <ouatubi@gmail.com> - 2016-02-22 01:46 -0800

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


#45676

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2016-02-22 16:20 +0100
Message-ID<86egc4sre0.fsf@molnjunk.nocrew.org>
In reply to#45648
"HAA" <someone@microsoft.com> writes:
> OFW practice what they preach:
>
> : do-buffer  ( apf -- adr )
>    dup >user @  if          ( apf )
>       >user @                 ( adr )
>    else                           ( apf )
>       dup /user# + @      ( apf size )
>       dup alloc-mem       ( apf size adr )
>       dup rot erase         ( apf adr )
>       dup rot >user !       ( adr )
>    then
> ;
>
> Which code would you prefer to work with - with or without the stack
> comments?

I like short words, so I might have written it something like this.

: alloc-erased ( size -- adr ) dup >r alloc-mem  dup r> erase ;

: /user ( apf -- size ) /user# + @ ;
: user@ ( apf -- adr ) >user @ ;
: user! ( adr apf -- ) >user ! ;
: alloc-user ( apf -- adr ) /user alloc-erased ;
: +user ( apf -- ) dup alloc-user swap user! ;
: ?+user ( apf -- apf ) dup user@ 0= if dup +user then ;

: do-buffer ( apf -- adr ) ?+user user@ ;

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


#45677

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2016-02-22 09:47 -0600
Message-ID<SOudnaTUetkJsFbLnZ2dnUU7-e-dnZ2d@supernews.com>
In reply to#45676
Lars Brinkhoff <lars.spam@nocrew.org> wrote:
> "HAA" <someone@microsoft.com> writes:
>> OFW practice what they preach:
>>
>> : do-buffer  ( apf -- adr )
>>    dup >user @  if          ( apf )
>>       >user @                 ( adr )
>>    else                           ( apf )
>>       dup /user# + @      ( apf size )
>>       dup alloc-mem       ( apf size adr )
>>       dup rot erase         ( apf adr )
>>       dup rot >user !       ( adr )
>>    then
>> ;
>>
>> Which code would you prefer to work with - with or without the stack
>> comments?
> 
> I like short words, so I might have written it something like this.
> 
> : alloc-erased ( size -- adr ) dup >r alloc-mem  dup r> erase ;
> 
> : /user ( apf -- size ) /user# + @ ;
> : user@ ( apf -- adr ) >user @ ;
> : user! ( adr apf -- ) >user ! ;
> : alloc-user ( apf -- adr ) /user alloc-erased ;
> : +user ( apf -- ) dup alloc-user swap user! ;
> : ?+user ( apf -- apf ) dup user@ 0= if dup +user then ;
> 
> : do-buffer ( apf -- adr ) ?+user user@ ;

Quite so, yes.

I was about to post somtthing similar, although not as extremely
factored as this.  IMO, rather than spend time annontating the stack
you might as well refactor instead.

Andrew.

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


#45692

FromWhammo <sidciavic@gmail.com>
Date2016-02-23 16:51 -0800
Message-ID<4b862821-c8a5-47a6-b5f7-a9b242048b9c@googlegroups.com>
In reply to#45676
On Monday, February 22, 2016 at 7:20:58 AM UTC-8, Lars Brinkhoff wrote:
> "HAA" <someone@microsoft.com> writes:
> > OFW practice what they preach:
> >
> > : do-buffer  ( apf -- adr )
> >    dup >user @  if          ( apf )
> >       >user @                 ( adr )
> >    else                           ( apf )
> >       dup /user# + @      ( apf size )
> >       dup alloc-mem       ( apf size adr )
> >       dup rot erase         ( apf adr )
> >       dup rot >user !       ( adr )
> >    then
> > ;
> >
> > Which code would you prefer to work with - with or without the stack
> > comments?
> 
> I like short words, so I might have written it something like this.
> 
> : alloc-erased ( size -- adr ) dup >r alloc-mem  dup r> erase ;
> 
> : /user ( apf -- size ) /user# + @ ;
> : user@ ( apf -- adr ) >user @ ;
> : user! ( adr apf -- ) >user ! ;
> : alloc-user ( apf -- adr ) /user alloc-erased ;
> : +user ( apf -- ) dup alloc-user swap user! ;
> : ?+user ( apf -- apf ) dup user@ 0= if dup +user then ;
> 
> : do-buffer ( apf -- adr ) ?+user user@ ;

 Brilliant! Anyone could sort out this code. 

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


#45728

From"HAA" <someone@microsoft.com>
Date2016-02-28 15:22 +1100
Message-ID<natsmo$1n77$1@gioia.aioe.org>
In reply to#45692
Whammo wrote:
> On Monday, February 22, 2016 at 7:20:58 AM UTC-8, Lars Brinkhoff wrote:
> > "HAA" <someone@microsoft.com> writes:
> > > OFW practice what they preach:
> > >
> > > : do-buffer  ( apf -- adr )
> > >    dup >user @  if          ( apf )
> > >       >user @                 ( adr )
> > >    else                           ( apf )
> > >       dup /user# + @      ( apf size )
> > >       dup alloc-mem       ( apf size adr )
> > >       dup rot erase         ( apf adr )
> > >       dup rot >user !       ( adr )
> > >    then
> > > ;
> > >
> > > Which code would you prefer to work with - with or without the stack
> > > comments?
> >
> > I like short words, so I might have written it something like this.
> >
> > : alloc-erased ( size -- adr ) dup >r alloc-mem  dup r> erase ;
> >
> > : /user ( apf -- size ) /user# + @ ;
> > : user@ ( apf -- adr ) >user @ ;
> > : user! ( adr apf -- ) >user ! ;
> > : alloc-user ( apf -- adr ) /user alloc-erased ;
> > : +user ( apf -- ) dup alloc-user swap user! ;
> > : ?+user ( apf -- apf ) dup user@ 0= if dup +user then ;
> >
> > : do-buffer ( apf -- adr ) ?+user user@ ;
>
>  Brilliant! Anyone could sort out this code.

You have 7 new words and stack effects to remember.
How is this brilliant?






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


#45729

Fromhughaguilar96@gmail.com
Date2016-02-27 21:30 -0800
Message-ID<69a094e4-7ab1-4a20-9896-6270665e4f2f@googlegroups.com>
In reply to#45728
On Saturday, February 27, 2016 at 9:22:52 PM UTC-7, HAA wrote:
> Whammo wrote:
> > On Monday, February 22, 2016 at 7:20:58 AM UTC-8, Lars Brinkhoff wrote:
> > > I like short words, so I might have written it something like this.
> > >
> > > : alloc-erased ( size -- adr ) dup >r alloc-mem  dup r> erase ;
> > >
> > > : /user ( apf -- size ) /user# + @ ;
> > > : user@ ( apf -- adr ) >user @ ;
> > > : user! ( adr apf -- ) >user ! ;
> > > : alloc-user ( apf -- adr ) /user alloc-erased ;
> > > : +user ( apf -- ) dup alloc-user swap user! ;
> > > : ?+user ( apf -- apf ) dup user@ 0= if dup +user then ;
> > >
> > > : do-buffer ( apf -- adr ) ?+user user@ ;
> >
> >  Brilliant! Anyone could sort out this code.
> 
> You have 7 new words and stack effects to remember.
> How is this brilliant?

Well, this was my code:

: do-buffer ( apf -- adr ) 
    dup >user @ if 
        >user @                             \ -- adr 
    else 
        dup /user# + @  dup alloc-mem       \ -- apf size adr 
        tuck  swap erase                    \ -- apf adr 
        tuck  swap >user !                  \ -- adr 
        then ; 

I was just considering this one word in isolation however. If code similar to this gets written often, then Lars' short words might improve the readability of the whole program. 

I agree with HAA however that factoring this much for one word isn't necessarily a good idea, unless that word is very complicated, but this one isn't really.

One problem with factoring so much, is that the reader doesn't know if all these little words will be used again and hence need to be remembered because they will show up again, or if all he has to do is figure out DO-BUFFER. Also, all those little words pollute the name-space and may cause clashes later.

In MFX I upgraded UR/Forth so that I could tag words as being temporary. Each word had a flags byte where the immediate-flag and smudge-flag were, and there were several bits available. I had a word LOCAL that could be used after a definition and would set the local-flag for that word. I also had a word END-MODULE that was used typically at the end of each file. END-LOCAL would traverse the entire dictionary looking for any word with a local-flag set, and it would then set the smudge-flag for that word. So, the words in the module would disappear from the dictionary search and would not clash with words in other modules. This improves the readability a lot because the reader can know which words he needs to grok (the ones without the LOCAL after them) because they will be used throughout the program, but he doesn't have to figure out the local words except as necessary to figure out the global words. This was one of the few cases in which I had to take recourse to assembly-language and carnal-knowledge --- the vast majority of MFX was just Forth-83 standard code --- I only had one short file of UR/Forth specific code in assembly-language.

Forth-83 had some weaknesses, but it was better than ANS-Forth. UR/Forth in its day was a very professional Forth system --- those were the good old days when programming in Forth was easy and straightforward --- not such a minder-binder like now.

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


#45730

Fromhughaguilar96@gmail.com
Date2016-02-27 21:33 -0800
Message-ID<b99311fa-e4a9-43a4-9eac-d014c654ef05@googlegroups.com>
In reply to#45729
On Saturday, February 27, 2016 at 10:30:44 PM UTC-7, hughag...@gmail.com wrote:
> In MFX I upgraded UR/Forth so that I could tag words as being temporary. Each word had a flags byte where the immediate-flag and smudge-flag were, and there were several bits available. I had a word LOCAL that could be used after a definition and would set the local-flag for that word. I also had a word END-MODULE that was used typically at the end of each file. END-LOCAL would traverse the entire dictionary looking for any word with a local-flag set, and it would then set the smudge-flag for that word. 

I meant, END-MODULE would traverse the dictionary --- typo.

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


#45731

From"Elizabeth D. Rather" <erather@forth.com>
Date2016-02-27 21:39 -1000
Message-ID<kKmdncoKPNKCOU_LnZ2dnUU7-SXNnZ2d@supernews.com>
In reply to#45728
On 2/27/16 6:22 PM, HAA wrote:
> Whammo wrote:
>> On Monday, February 22, 2016 at 7:20:58 AM UTC-8, Lars Brinkhoff wrote:
>>> "HAA" <someone@microsoft.com> writes:
>>>> OFW practice what they preach:
>>>>
>>>> : do-buffer  ( apf -- adr )
>>>>     dup >user @  if          ( apf )
>>>>        >user @                 ( adr )
>>>>     else                           ( apf )
>>>>        dup /user# + @      ( apf size )
>>>>        dup alloc-mem       ( apf size adr )
>>>>        dup rot erase         ( apf adr )
>>>>        dup rot >user !       ( adr )
>>>>     then
>>>> ;
>>>>
>>>> Which code would you prefer to work with - with or without the stack
>>>> comments?
>>>
>>> I like short words, so I might have written it something like this.
>>>
>>> : alloc-erased ( size -- adr ) dup >r alloc-mem  dup r> erase ;
>>>
>>> : /user ( apf -- size ) /user# + @ ;
>>> : user@ ( apf -- adr ) >user @ ;
>>> : user! ( adr apf -- ) >user ! ;
>>> : alloc-user ( apf -- adr ) /user alloc-erased ;
>>> : +user ( apf -- ) dup alloc-user swap user! ;
>>> : ?+user ( apf -- apf ) dup user@ 0= if dup +user then ;
>>>
>>> : do-buffer ( apf -- adr ) ?+user user@ ;
>>
>>   Brilliant! Anyone could sort out this code.
>
> You have 7 new words and stack effects to remember.
> How is this brilliant?

New words, yes, but the stacks don't have to be "remembered" since they 
are annotated appropriately. A proper implementation would include a 
LOCATE facility, and the likelihood that the components defined here 
would be used elsewhere in the app is high.

Cheers,
Elizabeth

-- 
==================================================
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc.                         +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

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


#45741

From"HAA" <someone@microsoft.com>
Date2016-02-29 13:47 +1100
Message-ID<nb0bik$1ftv$1@gioia.aioe.org>
In reply to#45731
Elizabeth D. Rather wrote:
> On 2/27/16 6:22 PM, HAA wrote:
> > Whammo wrote:
> >> On Monday, February 22, 2016 at 7:20:58 AM UTC-8, Lars Brinkhoff wrote:
> >>> "HAA" <someone@microsoft.com> writes:
> >>>> OFW practice what they preach:
> >>>>
> >>>> : do-buffer  ( apf -- adr )
> >>>>     dup >user @  if          ( apf )
> >>>>        >user @                 ( adr )
> >>>>     else                           ( apf )
> >>>>        dup /user# + @      ( apf size )
> >>>>        dup alloc-mem       ( apf size adr )
> >>>>        dup rot erase         ( apf adr )
> >>>>        dup rot >user !       ( adr )
> >>>>     then
> >>>> ;
> >>>>
> >>>> Which code would you prefer to work with - with or without the stack
> >>>> comments?
> >>>
> >>> I like short words, so I might have written it something like this.
> >>>
> >>> : alloc-erased ( size -- adr ) dup >r alloc-mem  dup r> erase ;
> >>>
> >>> : /user ( apf -- size ) /user# + @ ;
> >>> : user@ ( apf -- adr ) >user @ ;
> >>> : user! ( adr apf -- ) >user ! ;
> >>> : alloc-user ( apf -- adr ) /user alloc-erased ;
> >>> : +user ( apf -- ) dup alloc-user swap user! ;
> >>> : ?+user ( apf -- apf ) dup user@ 0= if dup +user then ;
> >>>
> >>> : do-buffer ( apf -- adr ) ?+user user@ ;
> >>
> >>   Brilliant! Anyone could sort out this code.
> >
> > You have 7 new words and stack effects to remember.
> > How is this brilliant?
>
> New words, yes, but the stacks don't have to be "remembered" since they
> are annotated appropriately.

The original definition has documented stack effects too (the same
number in fact).  IMO the stack comments worked better here than
the factors.  Factoring results in more names.  If they're not needed,
they become a distraction...

WONG'S RULES FOR READABLE FORTH (FPH)

3. Do not factor just to factor.

>  A proper implementation would include a
> LOCATE facility, and the likelihood that the components defined here
> would be used elsewhere in the app is high.

Re-use is of course a reason to factor, however I'd add the benefit must
be real.  As regards the code in question we'll just have to accept Mitch
Bradley chose not to factor it.


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


#45742

FromPaul Rubin <no.email@nospam.invalid>
Date2016-02-28 19:02 -0800
Message-ID<87wppote05.fsf@jester.gateway.pace.com>
In reply to#45741
"HAA" <someone@microsoft.com> writes:
> Factoring results in more names.  If they're not needed, they become a
> distraction... WONG'S RULES FOR READABLE FORTH (FPH)
> 3. Do not factor just to factor.

1. Who's Wong?

2. If the factors are scoped (maybe just by naming convention) so they
don't pullute the global namespace, is distraction still a problem?

If I want to split a word FOO into several factors that aren't going
to be used anywhere else, I generally call them FOO.1, FOO.2 etc.
That's the type of thing that asm programmers end up doing and it
seems to work afaict.

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


#45746

FromJulian Fondren <julian.fondren@gmail.com>
Date2016-02-28 22:26 -0800
Message-ID<6c5f2ad3-f29a-4582-8643-33a31127870a@googlegroups.com>
In reply to#45742
On Sunday, February 28, 2016 at 9:02:52 PM UTC-6, Paul Rubin wrote:
> "HAA" <someone@microsoft.com> writes:
> > Factoring results in more names.  If they're not needed, they become a
> > distraction... WONG'S RULES FOR READABLE FORTH (FPH)
> > 3. Do not factor just to factor.
>
> 1. Who's Wong?

Leo Wong.  http://www.murphywong.net/hello/forth.htm

You can find archives of his posts to this newsgroup on google.

His posts were remarkably free of internet toxins.


>
> 2. If the factors are scoped (maybe just by naming convention) so they
> don't pullute the global namespace, is distraction still a problem?
>

Or the convention that you just don't use them.  Leave them to
make sense in context, and only use whatever toplevel words you
come out with.  Another old clf name is kc5tja, who has this
video: https://www.youtube.com/watch?v=mvrE2ZGe-rs 

I really strongly recommend against his no-stack-comments 'book
index' formatting, based on how bewildered I was with my own
code that followed this style when I picked it up after some
time, but his casual attitude towards the dictionary and
redefinition is fine.  It also helps you follow Wong's advice of
"Don't bury your tools" (apart from how you sometimes bury them
'neath other tools.)

-- Julian

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


#45747

FromPaul Rubin <no.email@nospam.invalid>
Date2016-02-28 22:37 -0800
Message-ID<87si0ct42t.fsf@jester.gateway.pace.com>
In reply to#45746
Julian Fondren <julian.fondren@gmail.com> writes:
> Leo Wong.  http://www.murphywong.net/hello/forth.htm

Nice!

> Or the convention that you just don't use them.  Leave them to
> make sense in context, and only use whatever toplevel words you
> come out with.

But that leads to a lot of confusion keeping the stack straight, unless
you use locals freely.  Traditional (stack juggling) Forth code I've
seen tends to use factors the way other languages use local variables.

> It also helps you follow Wong's advice of "Don't bury your tools"
> (apart from how you sometimes bury them 'neath other tools.)

Burying the factors (by naming or scoping) under the words they compose
to seems ok, exposing everything in the global namespace for public use
gets messy as the program gets bigger.  C has in-function local
variables but it still added static functions (visible only in the local
module) after a while.  Maybe one aspect of Forth philosophy is to just
not allow the program to get that big, though.

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


#45743

Fromhughaguilar96@gmail.com
Date2016-02-28 19:11 -0800
Message-ID<d28e17e7-e85c-4f8f-bdf0-267182f3c35b@googlegroups.com>
In reply to#45741
On Sunday, February 28, 2016 at 7:49:01 PM UTC-7, HAA wrote:
> Elizabeth D. Rather wrote:
> >  A proper implementation would include a
> > LOCATE facility, and the likelihood that the components defined here
> > would be used elsewhere in the app is high.
> 
> Re-use is of course a reason to factor, however I'd add the benefit must
> be real.  As regards the code in question we'll just have to accept Mitch
> Bradley chose not to factor it.

I think we've analyzed this one little function to death. Now that we've had all of this classroom time, everybody is qualified to go out and write Forth programs! Start anytime...

Note for Albert: I don't know what APF means, or what DO-BUFFER does, or anything else either.

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


#45753

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2016-02-29 11:55 -0600
Message-ID<MqydnX2LL4y_G0nLnZ2dnUU78bHNnZ2d@supernews.com>
In reply to#45741
HAA <someone@microsoft.com> wrote:
> Elizabeth D. Rather wrote:
>
>> New words, yes, but the stacks don't have to be "remembered" since they
>> are annotated appropriately.
> 
> The original definition has documented stack effects too (the same
> number in fact).  IMO the stack comments worked better here than
> the factors.  Factoring results in more names.  If they're not needed,
> they become a distraction...

Perhaps you prefer not to factor, but instead you insert stack
comments.  That's something you're entitled to, of course.  However,
your original claim was:

> It makes perfect sense that a stack-based language needs stack-based
> commentary to be readable.  Take it out and the code becomes 'write
> only' - a frequent complaint of Forth.

... and I think we've shown this claim to be dubious, or at least
unproven.  Yes, if you don't factor enough you need inline stack
comments to make Forth readable.  But we already knew that.

Andrew

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


#45754

From"Elizabeth D. Rather" <erather@forth.com>
Date2016-02-29 19:30 -1000
Message-ID<Qa-dnWNx1IJItUjLnZ2dnUU7-bXNnZ2d@supernews.com>
In reply to#45741
On 2/28/16 4:47 PM, HAA wrote:
> Elizabeth D. Rather wrote:
>> On 2/27/16 6:22 PM, HAA wrote:
>>> Whammo wrote:
>>>> On Monday, February 22, 2016 at 7:20:58 AM UTC-8, Lars Brinkhoff wrote:
>>>>> "HAA" <someone@microsoft.com> writes:
>>>>>> OFW practice what they preach:
>>>>>>
>>>>>> : do-buffer  ( apf -- adr )
>>>>>>      dup >user @  if          ( apf )
>>>>>>         >user @                 ( adr )
>>>>>>      else                           ( apf )
>>>>>>         dup /user# + @      ( apf size )
>>>>>>         dup alloc-mem       ( apf size adr )
>>>>>>         dup rot erase         ( apf adr )
>>>>>>         dup rot >user !       ( adr )
>>>>>>      then
>>>>>> ;
>>>>>>
>>>>>> Which code would you prefer to work with - with or without the stack
>>>>>> comments?
>>>>>
>>>>> I like short words, so I might have written it something like this.
>>>>>
>>>>> : alloc-erased ( size -- adr ) dup >r alloc-mem  dup r> erase ;
>>>>>
>>>>> : /user ( apf -- size ) /user# + @ ;
>>>>> : user@ ( apf -- adr ) >user @ ;
>>>>> : user! ( adr apf -- ) >user ! ;
>>>>> : alloc-user ( apf -- adr ) /user alloc-erased ;
>>>>> : +user ( apf -- ) dup alloc-user swap user! ;
>>>>> : ?+user ( apf -- apf ) dup user@ 0= if dup +user then ;
>>>>>
>>>>> : do-buffer ( apf -- adr ) ?+user user@ ;
>>>>
>>>>    Brilliant! Anyone could sort out this code.
>>>
>>> You have 7 new words and stack effects to remember.
>>> How is this brilliant?
>>
>> New words, yes, but the stacks don't have to be "remembered" since they
>> are annotated appropriately.
>
> The original definition has documented stack effects too (the same
> number in fact).  IMO the stack comments worked better here than
> the factors.  Factoring results in more names.  If they're not needed,
> they become a distraction...
>
> WONG'S RULES FOR READABLE FORTH (FPH)
>
> 3. Do not factor just to factor.

Wong is right, but there are several reasons you might find it a good 
idea, and individual tastes may vary. It takes some experience to find 
the right balance.

>>   A proper implementation would include a
>> LOCATE facility, and the likelihood that the components defined here
>> would be used elsewhere in the app is high.
>
> Re-use is of course a reason to factor, however I'd add the benefit must
> be real.  As regards the code in question we'll just have to accept Mitch
> Bradley chose not to factor it.

Here are some of the indicators that there needs to be more factoring:

* Repeated phrases (opportunity for re-use)

* Testability (e.g., code to be used in a loop or CASE statement that is 
more than a very few words should be defined so it's easy to test for 
functionality, stack behavior, etc.)

* Reducing complexity (a definition with multiple loops and conditionals 
or multiple nested logical structures will be very much easier to test 
if it's factored into a few logical components.)

* Conceptual unity (a definition should really do exactly one thing, 
though that one thing may have several components, each of which does 
one thing. If the components aren't simple, they should be factored.)

There have been many attempts to describe this essential decision-making 
process, and they all boil down to a feeling for what makes sense. There 
are also rules of thumb like "only seven words" (based on the old but 
fairly well-documented observation that humans can carry up to 7 things, 
such as digits, in their heads at once, and if there are more they need 
to be factored somehow), but in Forth that can't be taken too literally, 
since some words are extremely simple, such as dup.

Cheers,
Elizabeth

-- 
==================================================
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc.                         +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

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


#45757

From"HAA" <someone@microsoft.com>
Date2016-03-02 00:49 +1100
Message-ID<nb46nq$1sif$1@gioia.aioe.org>
In reply to#45754
Elizabeth D. Rather wrote:
> On 2/28/16 4:47 PM, HAA wrote:
> > ...
> > The original definition has documented stack effects too (the same
> > number in fact).  IMO the stack comments worked better here than
> > the factors.  Factoring results in more names.  If they're not needed,
> > they become a distraction...
> >
> > WONG'S RULES FOR READABLE FORTH (FPH)
> >
> > 3. Do not factor just to factor.
>
> Wong is right, but there are several reasons you might find it a good
> idea, and individual tastes may vary. It takes some experience to find
> the right balance.
> ...

Yes, let's have some balance.

30 years of looking at forth code including that of vendors and
Bradley's definition looks very typical to me.  SwiftForth's code
is no different.

Whammo had no basis for factoring.  He factored until there was
nothing left - exactly what Wong said shouldn't be done.  Six of his
seven new words are used only once.  Moore has something to
say about that:

"Any time a word is used only once you want to question its value."




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


#45765

From"Elizabeth D. Rather" <erather@forth.com>
Date2016-03-01 13:50 -1000
Message-ID<N6-dnZfQxtxNt0vLnZ2dnUU7-dPNnZ2d@supernews.com>
In reply to#45757
On 3/1/16 3:49 AM, HAA wrote:
> Elizabeth D. Rather wrote:
>> On 2/28/16 4:47 PM, HAA wrote:
>>> ...
>>> The original definition has documented stack effects too (the same
>>> number in fact).  IMO the stack comments worked better here than
>>> the factors.  Factoring results in more names.  If they're not needed,
>>> they become a distraction...
>>>
>>> WONG'S RULES FOR READABLE FORTH (FPH)
>>>
>>> 3. Do not factor just to factor.
>>
>> Wong is right, but there are several reasons you might find it a good
>> idea, and individual tastes may vary. It takes some experience to find
>> the right balance.
>> ...
>
> Yes, let's have some balance.
>
> 30 years of looking at forth code including that of vendors and
> Bradley's definition looks very typical to me.  SwiftForth's code
> is no different.
>
> Whammo had no basis for factoring.  He factored until there was
> nothing left - exactly what Wong said shouldn't be done.  Six of his
> seven new words are used only once.  Moore has something to
> say about that:
>
> "Any time a word is used only once you want to question its value."

As I mentioned in my other post, there are some situations in which 
there is value, such as the ability to independently test a component of 
an operation that is referenced in a loop, CASE statement, or other 
structure, or just the fact that the component is sufficiently complex 
in itself that it will be useful to test and document it in isolation.

I agree that Whammo went a bit far, but looking at the long original 
definition I think some factoring was in order.

Cheers,
Elizabeth

-- 
==================================================
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc.                         +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

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


#45766

FromPaul Rubin <no.email@nospam.invalid>
Date2016-03-01 16:49 -0800
Message-ID<878u211z7a.fsf@nightsong.com>
In reply to#45757
"HAA" <someone@microsoft.com> writes:
> Moore has something to say about that:
> "Any time a word is used only once you want to question its value."

Won't any serious compiler always inline words like that?  Also Chuck's
own code that I've looked at has lots of such words.

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


#45769

Fromhughaguilar96@gmail.com
Date2016-03-01 18:04 -0800
Message-ID<ed58b652-bb00-488a-83e3-83c646473363@googlegroups.com>
In reply to#45766
On Tuesday, March 1, 2016 at 5:49:15 PM UTC-7, Paul Rubin wrote:
> "HAA" <someone@microsoft.com> writes:
> > Moore has something to say about that:
> > "Any time a word is used only once you want to question its value."
> 
> Won't any serious compiler always inline words like that?  Also Chuck's
> own code that I've looked at has lots of such words.

I recently wrote another file for the novice package --- string-stack.4th

My goal here was to get ANS-Forth up to the level of QBASIC in regard to text handling. I have already shown it to several Forthers. Anybody who is interested can email me and get it.

Packages like this help a lot. Without this, you would have to write code to work with strings as adr/cnt pairs on the data-stack. You would have to allocate and free the strings on the heap manually. The code would be complicated...

It seems ridiculous that all the self-proclaimed Forth experts are in this thread pontificating on the subject of how much Forth words should be factored and how much they should be commented. All of this is nonsense. What Forth needs is code-libraries to make programming easy --- when everything is done manually, the application programs are going to be horrendously complicated, and all this hot air from the experts isn't going to help.

The major problem with Forth is that there is a hatred for general-purpose code. I have never met Charles Moore, so I don't know if this really came from him, although all the comp.lang.forth experts quote him to support their own hatred for general-purpose code. It is most likely that Charles Moore was somewhat opposed to general-purpose code (hence the quotes) but the whole issue has been blown out of proportion by Elizabeth Rather --- she seems to have taken that one idea and blown it up to gigantic proportions.

What would Charles Moore think of my string-stack.4th code? Maybe he would totally hate it and he would say that I'm not a Forther at all as I am doing everything wrong. Maybe not though.

In the meantime, Elizabeth Rather will certainly hate it and say that I'm not a Forther at all as I am doing everything wrong. This is the reality of comp.lang.forth --- you can't use string-stack.4th without offending Elizabeth Rather --- I don't think any of you internet-experts are brave enough to do that.

I predict that everybody will continue pontificating on Forth style, and nobody will write any Forth code --- same as usual.

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


#45774

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2016-03-02 02:53 -0600
Message-ID<sYSdnZUycP-dN0vLnZ2dnUU78bGdnZ2d@supernews.com>
In reply to#45766
Paul Rubin <no.email@nospam.invalid> wrote:
> "HAA" <someone@microsoft.com> writes:
>> Moore has something to say about that:
>> "Any time a word is used only once you want to question its value."
> 
> Won't any serious compiler always inline words like that? 

The base of Forth's design has always been that calls are cheap.  The
paramater-passing mechanism makes them as cheap as possible.  So, no,
you don't have to inline to be serious.

> Also Chuck's own code that I've looked at has lots of such words.

Indeed.  So, yes, you question its value.  But the fact that a word is
only used once is not a sufficient reason to remove it.

Andrew.

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


#45775

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2016-03-02 09:57 +0000
Message-ID<2016Mar2.105720@mips.complang.tuwien.ac.at>
In reply to#45766
Paul Rubin <no.email@nospam.invalid> writes:
>"HAA" <someone@microsoft.com> writes:
>> Moore has something to say about that:
>> "Any time a word is used only once you want to question its value."
>
>Won't any serious compiler always inline words like that?

No Forth compiler I know of does that (maybe they are all not
serious:-).  Why don't they?  Because there is no way for the compiler
to know how many calls to the word there will be when it compiles a
call to the word.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/

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


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

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


csiph-web