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 4 of 6 — ← Prev page 1 2 3 [4] 5 6  Next page →


#47721

Fromhughaguilar96@gmail.com
Date2016-06-02 00:17 -0700
Message-ID<55e644b4-6e56-49bc-acb0-36bcee01763d@googlegroups.com>
In reply to#47720
On Wednesday, June 1, 2016 at 11:48:31 PM UTC-7, Lars Brinkhoff wrote:
> Unknown:
> > "Well commented" tries to use this fact that humans are VISUAL.
> > [dogs and ants are said to work via smells]
> 
> Supposedly, some programmers are sensitive to code smells.  Maybe some
> kind of nose attachment would be a good user interface.

I think that a good argument can be made that human's greatest invention was the written alphabet. Before that, people just drew pictures to communicate. Over time these pictures were standardized into hieroglyphs, but this still didn't work well because they were hard to remember and they were ambiguous because the number had to be kept low and so each one had multiple meanings. All in all, the alphabet was the big breakthrough.

Now, with the GUI we are back to using hieroglyphs again --- they are called "icons" --- but they are still just little pictures the same as hieroglyphs but with less standardization and with fewer of them (AutoCAD has dozens, whereas Chinese has thousands).

I don't think this guy is right about humans being visual-oriented (pictures) --- I think that humans are text-oriented --- animals are visual-oriented.

But, to succeed as a species we have to stick with what we are good at --- going back to little pictures is a step backwards --- possibly enough of a step backwards to bring extinction to our species (with our population as large as it is, we can't afford to take backwards steps; we have to move forward, or die).

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


#47772

FromMichael Barry <barrym95838@yahoo.com>
Date2016-06-02 19:48 -0700
Message-ID<738f6bea-c241-4286-a3e2-29d50ebda093@googlegroups.com>
In reply to#47720
On Wednesday, June 1, 2016 at 11:48:31 PM UTC-7, Lars Brinkhoff wrote:
> Unknown:
> > "Well commented" tries to use this fact that humans are VISUAL.
> > [dogs and ants are said to work via smells]
> 
> Supposedly, some programmers are sensitive to code smells.  Maybe some
> kind of nose attachment would be a good user interface.

Could you or anyone here please take a look at my buggy line drawing
 routine at ...

http://forum.6502.org/viewtopic.php?p=36614#p36614

... and steer me in the proper direction?  It doesn't draw correctly,
 and it seems that it should be factored some way or another, but I
 just don't have enough experience or perseverance to get it right.

TIA,

Mike B.

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


#47773

Fromhughaguilar96@gmail.com
Date2016-06-02 20:34 -0700
Message-ID<197ef593-62fb-4e28-89be-08c405d1359b@googlegroups.com>
In reply to#47772
On Thursday, June 2, 2016 at 7:48:45 PM UTC-7, Michael Barry wrote:
> On Wednesday, June 1, 2016 at 11:48:31 PM UTC-7, Lars Brinkhoff wrote:
> > Unknown:
> > > "Well commented" tries to use this fact that humans are VISUAL.
> > > [dogs and ants are said to work via smells]
> > 
> > Supposedly, some programmers are sensitive to code smells.  Maybe some
> > kind of nose attachment would be a good user interface.
> 
> Could you or anyone here please take a look at my buggy line drawing
>  routine at ...
> 
> http://forum.6502.org/viewtopic.php?p=36614#p36614
> 
> ... and steer me in the proper direction?  It doesn't draw correctly,
>  and it seems that it should be factored some way or another, but I
>  just don't have enough experience or perseverance to get it right.
> 
> TIA,
> 
> Mike B.

I skimmed over that thread. I didn't examine your code carefully.

I will say that line drawing is an example I have used previously in regard to how to write Forth code.

You don't want a function with a lot of parameters such as these:

: draw-line ( ax ay bx by -- ) ... ;
: intersect-lines ( ax ay bx by dx dy ex ey -- x y intersected? )

Having a lot of parameters quickly becomes a nightmare of stack-juggling. Using locals helps, but it is still horrible design.

You are better off to use structs:

0
    w field .x
    w field .y
constant point

0
    point field .a
    point field .b
constant line

point
    w field .r
constant circle

: draw-line ( line -- ) ... ;
: intersect-lines ( lineA lineB -- point intersected? ) ... ;

In the above functions, line and lineA and lineB are all pointers to structs of type LINE. Structs are kept on the heap. The function INTERSECT-LINES returns a pointer to a struct of type POINT and a flag indicating if the lines intersected.

I have a lot of examples of structs in the novice-package. See LIST.4TH for some simple examples.

Here are some constructors (I haven't tested this, but it is pretty obvious and should work). Note that ALLOC is like ALLOCATE but does the error-checking rather than give you a flag.

: init-point ( x y node -- node )
    >r
    r@ .y !
    r@ .x !
    r> ;

: new-point ( x y -- node )
    point alloc
    init-point ;

: init-circle ( r x y node -- node )
    init-point >r
    r@ .r !
    r> ;

: new-circle ( r x y -- node )
    circle alloc
    init-circle ;

Notice that the constructor is factored into INIT-xxx and NEW-xxx words. The purpose of this is so the INIT-xxx word can be used inside of the INIT-yyy word of a child class. In the above example, the CIRCLE class is a child of the POINT class. This is a crude form of OOP --- this is all I do in regard to OOP in the novice-package --- I have found that this works quite well for simplifying code.

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


#45681

From"WJ" <w_a_x_man@yahoo.com>
Date2016-02-22 19:23 +0000
Message-ID<nafn7t$894$1@dont-email.me>
In reply to#45648
HAA wrote:

> 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?  It's a 'no brainer'.  Yet forthers persist writing them without.

: do-buffer  { apf -- adr }
  apf >user @
  if  apf >user @
  else
    apf /user# + @ { size}
    size alloc-mem { adr}
    adr size erase
    adr apf >user !
    adr
  then ;

-- 
Goyim were born only to serve us. Without that, they have no place in the
world---only to serve the People of Israel....  They will work, they will plow,
they will reap. We will sit like an effendi and eat. --- Rabbi Ovadia Yosef
http://archive.org/download/DavidDuke_videos/TopRabbiExposesJewishRacism-cybsdwjezqi.ogv
https://web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld/JewishNews/Article.aspx?id=191782

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


#45697

From"HAA" <someone@microsoft.com>
Date2016-02-25 20:31 +1100
Message-ID<namhmb$hsv$1@gioia.aioe.org>
In reply to#45681
WJ wrote:
> HAA wrote:
>
> > 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?  It's a 'no brainer'.  Yet forthers persist writing them without.
>
> : do-buffer  { apf -- adr }
>   apf >user @
>   if  apf >user @
>   else
>     apf /user# + @ { size}
>     size alloc-mem { adr}
>     adr size erase
>     adr apf >user !
>     adr
>   then ;

Very good but locals demand a price for their magic.  Stack comments
cost nothing.


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


#45701

FromJulian Fondren <julian.fondren@gmail.com>
Date2016-02-25 07:44 -0800
Message-ID<231274df-77c0-4eb3-98f9-ed73d53cb92b@googlegroups.com>
In reply to#45697
On Thursday, February 25, 2016 at 3:32:00 AM UTC-6, HAA wrote:
> 
> Very good but locals demand a price for their magic.  Stack comments
> cost nothing.
>

When you edit the code, you also have to edit the stack comments.
When the stack comments are horizontally offset like this, you have
to maintain that offset.  If you add too many words to a line you
must decide between changing the offset or reformatting the code to
fit -- and recreating the stack comments to suit the new format.
When you edit the code or after others have edited the code you must
also consider that the stack comments may now be wrong.  When you
change the stack effect of a word you must now change the stack
comments of words that use it -- oftentimes, words have a protocol
of use that renders unimportant their actual stack effect.  Like

   : blah [ .s ( what is the stack here?  who cares?) ] ;
 
   class blah
     cell var a
     .s ( what is the stack here?  who cares?)
   end-class

   ( modified ciforth )
   DATA _value_jumps '@ , '! , '+! ,
   0 CONSTANT FROM
   1 CONSTANT TO
   2 CONSTANT +TO
   : VALUE CREATE , DOES> SWAP CELLS _value_jumps + @ EXECUTE ;

   5 VALUE X
   FROM X .  \ outputs: 5
   2 TO X
   FROM X .  \ outputs: 2

(Of course the usual X-by-itself usage doesn't work very well here,
which is why ciforth uses a variable instead of the stack.)

But the point is, when you do have protocol, it often doesn't matter
if you change the stack effect of the words in that protocol.

If PRODUCER MODIFIER MODIFIER MODIFIER CONSUMER always works just
like that, why should you have to run around changing the right-hand
side of

  PRODUCER           ( x x f  )
    MODIFIER         ( x x' f )
    MODIFIER         ( x' x f )
    MODIFIER         ( x x f' )
  CONSUMER           (        )

when you realize you don't need the flag anymore?


Comments are not free.  They have a cost.  Traditional
once-at-the-head-of-the-definition stack comments are well worth it.
Comments on every line would just be tedious to read, and a chore to
maintain.

Speaking of "on every line": why even limit yourself to once a line?
And doesn't it suddenly matter how horizontal your code is?  How
about "a stack comment after every three words"?  They're free,
after all, and they just add so much to readability, and how could
anyone possibly read four whole words and pretend to be able to keep
the stack in their head?


-- Julian

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


#45704

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2016-02-25 20:22 +0100
Message-ID<86io1cr3w6.fsf@molnjunk.nocrew.org>
In reply to#45701
Julian Fondren <julian.fondren@gmail.com> writes:
> But the point is, when you do have protocol, it often doesn't matter
> if you change the stack effect of the words in that protocol.

I have seen it argued that you can write most of your Forth code like
that.  I believe some call it problem-oriented programming, but I may be
wrong, or it may mean different things to different people.  In that
style, the programmer doesn't need to think much about the stack at all.
They say.

I haven't been able to write Forth programs like that, but I'd like to
learn some day.

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


#45727

From"HAA" <someone@microsoft.com>
Date2016-02-28 13:43 +1100
Message-ID<natmsu$1h19$1@gioia.aioe.org>
In reply to#45701
Julian Fondren wrote:
> On Thursday, February 25, 2016 at 3:32:00 AM UTC-6, HAA wrote:
> >
> > Very good but locals demand a price for their magic.  Stack comments
> > cost nothing.
> >
>
> When you edit the code, you also have to edit the stack comments.
> When the stack comments are horizontally offset like this, you have
> to maintain that offset.

Mitch Bradley uses a style that works for him.  I insert a comment
representing the current stack status between words where and when
I feel the need.

> Comments are not free.  They have a cost.  Traditional
> once-at-the-head-of-the-definition stack comments are well worth it.
> Comments on every line would just be tedious to read, and a chore to
> maintain.

Stack comments are free when they're *working* comments.
I never add anything I don't use.  Perhaps Mitch Bradley too.


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


#45732

From"Elizabeth D. Rather" <erather@forth.com>
Date2016-02-27 21:43 -1000
Message-ID<kPydnbB5Y8i8OE_LnZ2dnUU7-LWdnZ2d@supernews.com>
In reply to#45727
On 2/27/16 4:43 PM, HAA wrote:
> Julian Fondren wrote:
>> On Thursday, February 25, 2016 at 3:32:00 AM UTC-6, HAA wrote:
>>>
>>> Very good but locals demand a price for their magic.  Stack comments
>>> cost nothing.
>>>
>>
>> When you edit the code, you also have to edit the stack comments.
>> When the stack comments are horizontally offset like this, you have
>> to maintain that offset.
>
> Mitch Bradley uses a style that works for him.  I insert a comment
> representing the current stack status between words where and when
> I feel the need.
>
>> Comments are not free.  They have a cost.  Traditional
>> once-at-the-head-of-the-definition stack comments are well worth it.
>> Comments on every line would just be tedious to read, and a chore to
>> maintain.

What cost? Yes, it's possible to overdo, but brief usage notes in 
addition to the *obligatory* stack comment can only be an asset, not a 
liability. The maintenance "cost" is recouped many times over if you 
have turnover in your program staff or (*gasp*) can't personally 
remember everything year after year.

> Stack comments are free when they're *working* comments.
> I never add anything I don't use.  Perhaps Mitch Bradley too.

Mitch's comments are sparse but quite useful. I have read a lot of his code.

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]


#45735

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2016-02-28 14:53 +0000
Message-ID<2016Feb28.155355@mips.complang.tuwien.ac.at>
In reply to#45732
"Elizabeth D. Rather" <erather@forth.com> writes:
>On 2/27/16 4:43 PM, HAA wrote:
>> Julian Fondren wrote:
>>> On Thursday, February 25, 2016 at 3:32:00 AM UTC-6, HAA wrote:
>>>>
>>>> Very good but locals demand a price for their magic.  Stack comments
>>>> cost nothing.
>>>>
>>>
>>> When you edit the code, you also have to edit the stack comments.
>>> When the stack comments are horizontally offset like this, you have
>>> to maintain that offset.
...
>>> Comments are not free.  They have a cost.  Traditional
>>> once-at-the-head-of-the-definition stack comments are well worth it.
>>> Comments on every line would just be tedious to read, and a chore to
>>> maintain.
>
>What cost?

The cost that I am most worried about is that comments can go
out-of-sync with the code they comment.  There is no automatic way to
check this, so either you have to check the stack comments every time
you read the code, or the comments may lead you astray.  I consider
that a big cost.  For the stack-effect comment for a word, that is
less likely to happen, because one normally wants to keep the
interface the same (not sure if this is also the case with the kind of
very short one-off definitions that has been suggested here).

In contrast, if you get the locals wrong, the mistake shows up in
testing.  The price for locals therefore seems lower to me than the
price for stack comments.

- 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]


#45740

Fromhughaguilar96@gmail.com
Date2016-02-28 15:27 -0800
Message-ID<0715ee08-6774-44ec-a7d4-7d83a48d6e2f@googlegroups.com>
In reply to#45732
On Sunday, February 28, 2016 at 12:43:31 AM UTC-7, Elizabeth D. Rather wrote:
> On 2/27/16 4:43 PM, HAA wrote:
> >> Comments are not free.  They have a cost.  Traditional
> >> once-at-the-head-of-the-definition stack comments are well worth it.
> >> Comments on every line would just be tedious to read, and a chore to
> >> maintain.
> 
> What cost? Yes, it's possible to overdo, but brief usage notes in 
> addition to the *obligatory* stack comment can only be an asset, not a 
> liability. The maintenance "cost" is recouped many times over if you 
> have turnover in your program staff or (*gasp*) can't personally 
> remember everything year after year.

I suppose Forth Inc. has quite a lot of turnover in their programming staff. Here is an example of code released in version-2 of SwiftForth in which we have more comments than code.

ICODE ALIGNED ( a -- a )
   RET END-CODE                     \ aligned is noop, no alignment enforced

ICODE ALIGN ( -- )
   RET END-CODE                     \ align is noop, no alignment enforced

Are the "programming staff" who wrote this still working at Forth Inc.? And, on a related note, why do you demand that version-2 owners pay an additional $300 to upgrade to version-3? You know perfectly well that version-2 was a scam, but you don't want to make things right with your customers --- you just want to scam them again for another $300.

> > Stack comments are free when they're *working* comments.
> > I never add anything I don't use.  Perhaps Mitch Bradley too.
> 
> Mitch's comments are sparse but quite useful. I have read a lot of his code.

Reading other people's code doesn't make you a programmer --- because you are not a programmer, it is offensive for you to criticize programmers' work. 

You have never written a computer program in your life. All of of the code that you have posted on comp.lang.forth was copied directly out of the "Starting Forth" book. You remember Charles Moore's platitudes about programming that he mentioned in the 1970s and you have made a career out of spouting these platitudes as if they were your own --- but this doesn't make you a programmer --- even when these platitudes have some truth to them, they turn to crap when they come out of your mouth.

Note that I haven't read a lot of anybody's code --- who has time for that?

Anyway, this subject of stack-comments has already been discussed previously several times on comp.lang.forth.. Here is a typical example:

On Friday, September 20, 2013 at 8:52:47 PM UTC-7, Elizabeth D. Rather wrote:
> On 9/20/13 4:48 PM, Ed wrote:
> > Elizabeth D Rather wrote:
> >> ...
> >> Never, never, never write a definition without a stack comment.
> >> ...
> >
> > Funny because that's *exactly* how some Forth Wizards write their code.
> > Maintenance by others aside, *how* they manage to work that way without
> > getting lost is difficult to comprehend.
> >
> > Who am I talking about?  Well, there is Chuck Moore (source for Colorforth
> > is uncommented) and Stackworks author Mike Brothers wherein the entire
> > system source there is not a single stack comment.
> 
> That's sad. Chuck basically invented stack comments, and insisted on 
> their use when he was doing applications. FORTH, Inc. requires them, and 
> the best programmers I've worked with for many years (alas, I haven't 
> worked with Chuck since 1982) always include stack comments.
> 
> For learners, stack comments are especially helpful, since by having to 
> state them at the beginning of the definition they're led to focus on 
> the stack going in and coming out, and the comment is there to remind 
> them. One of the early simple exercises in Forth Application Techniques 
> involves printing out [n] stars, which many define as:
> 
> : STARS ( n -- )   0 DO ." * " LOOP  DROP ;
> 
> The ones who include the stack comment are far less likely to just type 
> STARS without an argument or forget the DROP at the end. But the 
> consequences of forgetting the number are also a good teaching moment. ;-)
> 
> Cheers,
> Elizabeth

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


#47722

Fromhumptydumpty <ouatubi@gmail.com>
Date2016-06-02 02:02 -0700
Message-ID<d2255ab6-a4ae-4530-bfe7-edff9b8c138b@googlegroups.com>
In reply to#45648
On Sunday, February 21, 2016 at 4:33:05 AM UTC+2, HAA wrote:
> hughaguilar wrote:
> > On Thursday, February 18, 2016 at 12:48:59 AM UTC-7, HAA wrote:
> > > Elizabeth D. Rather wrote:
> > > > On 2/15/16 9:28 PM, Anton Ertl wrote:
> > > > > "HAA" writes:
> > > > ...
> > > > >>   So how do they handle multi-line definitions?  In the same
> > > > >> way as raw beginners - by jotting down stack effects as they go.
> > > > >> These working comments are removed when the definition is complete.
> > > > >
> > > > > Maybe you work that way, I don't.  When the stack work is complex
> > > > > enough to write down stack pictures, I keep them.  They then also help
> > > > > in reading the code.
> > >
> > > Very rarely do I see stack comments within the body of a definition.
> >
> > I do that all the time.
> >
> > As a rule, whenever I have a BEGIN WHILE REPEAT loop, I put the BEGIN WHILE on one line
> > with a stack-picture after it.
> > ...
> 
> 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.
> 
> Forth primers are largely silent on this topic.  The closest I found was the
> Open Firmware guidelines published in FPH (section 8.2).
> 
>         8.2.8 Stack Comments
>         Stack comments begin with (_ and end with ).
>  ***   Use stack comments liberally within definitions.  ***
>         Try to structure each definition so that, when you put stack
>         comments at the end of each line, the stack picture
>         makes a nice pattern.
> 
> 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?  It's a 'no brainer'.  Yet forthers persist writing them without.

Hi!
A factored version:

: >user#      ( apf  -- size)  /user# + @ ;
: user-alloc  ( size -- a   )  dup alloc-mem dup rot erase ;
: new-user    ( apf --      )  dup >user# user-alloc swap >user ! ;
: no-user?    ( apf --  f   )  >user @ 0= ;

: do-buffer   ( apf -- adr)
        dup no-user? IF dup new-user THEN
        >user @
;

Have a nice day,
humptydumpty

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


#47795

FromJennyB <jennybrien@googlemail.com>
Date2016-06-03 05:57 -0700
Message-ID<06f18a2a-f2a9-4462-a3c3-66a0b68401f5@googlegroups.com>
In reply to#45648
On Sunday, 21 February 2016 02:33:05 UTC, HAA  wrote:

> Forth primers are largely silent on this topic.  The closest I found was the
> Open Firmware guidelines published in FPH (section 8.2).
> 
>         8.2.8 Stack Comments
>         Stack comments begin with (_ and end with ).
>  ***   Use stack comments liberally within definitions.  ***
>         Try to structure each definition so that, when you put stack
>         comments at the end of each line, the stack picture
>         makes a nice pattern.
> 
> 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
> ;
> 

I may be odd, but I like stack comments on the left, like pseudo-locals, so they precede the code that consumes them. Only name stack items that have changed. Indent for new items; outdent when they are consumed:

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

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


#45761

FromBernd Paysan <bernd.paysan@gmx.de>
Date2016-03-01 16:38 +0000
Message-ID<nb4gi6$egg$2@dont-email.me>
In reply to#45556
Am Tue, 16 Feb 2016 13:35:05 +1100 schrieb HAA:
> Despite advice about factoring, experienced forthers continue to write
> multi-line definitions.  Lots of them.  Why?  Because factoring does
> little to reduce memory load.  They factor when there's something worth
> factoring.  So how do they handle multi-line definitions?  In the same
> way as raw beginners - by jotting down stack effects as they go.

No, I really do it in my head.  When I actually have to write down stack 
effects, I keep those comments.  All the other experienced Forthers I 
know do the same.  The beginners struggle way more, of course.  If you 
need such a comment to write a word, you'll also need it to read and 
maintain it later, so it has to stay in place.

Maybe when you get more experienced, you can remove overly verbose stack 
commenting.  But if you have 20+ years of experience, any progress in 
your ability to deal with multi-line words is unlikely.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
net2o ID: kQusJzA;7*?t=uy@X}1GWr!+0qqp_Cn176t4(dQ*
http://bernd-paysan.de/

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


#45491

FromChris Curl <ccurl609@gmail.com>
Date2016-02-12 16:31 -0800
Message-ID<6803465f-364a-46ef-9fdd-6dfe43e72397@googlegroups.com>
In reply to#45489
It depends on the context.

If I am doing it in my head, I simply use my fingers to keep track of
the depth. There are usually few enough that I only need one hand.

If I am defining a word in the editor, I will use comments In the code.

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


#45492

FromWhammo <sidciavic@gmail.com>
Date2016-02-12 17:31 -0800
Message-ID<f3d941d6-53c7-48c6-a211-b9b451dccd45@googlegroups.com>
In reply to#45489
On Friday, February 12, 2016 at 1:57:08 PM UTC-8, lahe...@gmail.com wrote:
> When I'm reading forth code, I have to work hard to remember the contents of the stack. Especially when a word is more than a few subwords long, or contains words whose stack effects I have to go and look up, I am likely to forget what the stack looks like at the point I was just at. So I have to backtrack to a previous known stack state, and recover the context by reading word by word.
> 
> One thing I do is mentally "say" the contents of the stack after every word: "a b c...b c a...c a..." etc. This seems to help my memory. But I sometimes find I'm using so much attention remembering the stack that I don't have as much short-term memory left over as I would like for understanding the program itself.
> 
> Part of this is that I'm still pretty new, but I am wondering if you have any similar experiences or strategies to share.

 What you're reading is written in a bad coding style. 
If a forth word is more than one or two lines, that's a pretty good indication.
 When originally written, it was likely nicely factored, tested and intelligible. Then, familiar with the code, they pressed it into a foreign indented style to show how smart they are, rendering it nearly incomprehensible.

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


#45494

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2016-02-13 08:03 +0100
Message-ID<86ziv5um5t.fsf@molnjunk.nocrew.org>
In reply to#45489
laheadle@gmail.com writes:
> When I'm reading forth code, I have to work hard to remember the
> contents of the stack. Especially when a word is more than a few
> subwords long

That's why I try to write words so simple that the stack effect is quite
obvious.  As soon as I'm becoming confused about the state of the stack
inside a word, I break it up into smaller words.

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


#45495

Fromdunno <dunno@dunno.dunno>
Date2016-02-13 08:06 +0000
Message-ID<579900110.477043450.336442.dunno-dunno.dunno@news.mixmin.net>
In reply to#45489
<laheadle@gmail.com> wrote:
> When I'm reading forth code, I have to work hard to remember the contents
> of the stack. Especially when a word is more than a few subwords long, or
> contains words whose stack effects I have to go and look up, I am likely
> to forget what the stack looks like at the point I was just at. So I have
> to backtrack to a previous known stack state, and recover the context by
> reading word by word.
> 
> One thing I do is mentally "say" the contents of the stack after every
> word: "a b c...b c a...c a..." etc. This seems to help my memory. But I
> sometimes find I'm using so much attention remembering the stack that I
> don't have as much short-term memory left over as I would like for
> understanding the program itself.
> 
> Part of this is that I'm still pretty new, but I am wondering if you have
> any similar experiences or strategies to share.
> 

You already got some good advices. I just would like to add that you don't
have to keep everything on the stack. Feel free to use variables and locals
where it helps, especially if code is not time-consumable.

-- 
dunno

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


#45496

Fromminforth@arcor.de
Date2016-02-13 01:50 -0800
Message-ID<9479860c-a779-4ab8-9e64-1e0c5f761b41@googlegroups.com>
In reply to#45495
This leads me to the following silly question:

Is there a clever algorithm that converts locals syntax to stack juggling for Forths that have no locals implemented?

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


#45498

Frommhx@iae.nl
Date2016-02-13 03:22 -0800
Message-ID<defde842-5a9f-48a7-a653-c19d93f24c11@googlegroups.com>
In reply to#45496
On Saturday, February 13, 2016 at 10:50:54 AM UTC+1, minf...@arcor.de wrote:
> This leads me to the following silly question:
>
> Is there a clever algorithm that converts locals syntax to stack
> juggling for Forths that have no locals implemented?

The question is not silly, but imprecise.

If one wants to take the code as is on a Forth not having locals,
you're asking if it is possible to implement locals in high-level.
The answer is yes, e.g. Wil Baden's solution for FP also works
for integers. 

(If you accept that the source code is changed, it becomes
a question of the algorithm does and what the programmer 
changes, making it a really ill-posed problem.)

Your next move would probably be to state that you don't like 
the way this high-level solution works (it uses the dictionary 
like Wil's solution, or has an extra stack), and you constrain 
the solution by requiring it to only use the data stack. 
However, in that case the 'clever algorithm' needs to know 
the stack effect of every Forth word that is used in the word 
that you are translating. This is a feature that not many
Forths support (LINA maybe?). As some Forth words do *not
have* a constant stack effect (e.g. EXECUTE), your 'clever
algorithm' is turning into something that is many times
bigger and complicated than the problem you wanted to
solve (and it would force you to switch to Lina). As 
that is not Forth-like, you would drop the constraint and 
use, e.g., Wil Baden's solution, probably combined with
Anton Ertl's ideas in anslocal.fs to allow arbitrary names.

The optimizing Forth compilers I know have a locals
stack, but when they can figure out that the CPU
has enough resources to fit everything in
registers they don't use it. In doing that,
they also remove most or all data stack
manipulations. In a sense that is a solution
that fits your requirement + constraint, but
I am sure you also don't want to hear this
possibility :-)

-marcel

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


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

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


csiph-web