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


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

Is it -2ROT or 2-ROT ?

Started byRod Pemberton <NeedNotReplyHere@xrsevnneqk.cem>
First post2017-05-13 18:00 -0400
Last post2017-05-17 00:54 +1000
Articles 14 on this page of 34 — 16 participants

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


Contents

  Is it -2ROT or 2-ROT ? Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2017-05-13 18:00 -0400
    Re: Is it -2ROT or 2-ROT ? Julian Fondren <julian.fondren@gmail.com> - 2017-05-13 15:19 -0700
    Re: Is it -2ROT or 2-ROT ? "Elizabeth D. Rather" <erather@forth.com> - 2017-05-13 13:21 -1000
    Re: Is it -2ROT or 2-ROT ? "HAA" <someone@microsoft.com> - 2017-05-14 11:23 +1000
    Is it -2ROT or 2-ROT ? Mark Wills <markwills1970@gmail.com> - 2017-05-14 00:34 -0700
      Re: Is it -2ROT or 2-ROT ? "HAA" <someone@microsoft.com> - 2017-05-15 10:12 +1000
      Re: Is it -2ROT or 2-ROT ? rickman <gnuarm@gmail.com> - 2017-05-14 23:43 -0400
        Re: Is it -2ROT or 2-ROT ? "HAA" <someone@microsoft.com> - 2017-05-15 13:47 +1000
          Re: Is it -2ROT or 2-ROT ? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-05-15 09:51 +0000
        Re: Is it -2ROT or 2-ROT ? Paul Rubin <no.email@nospam.invalid> - 2017-05-14 21:42 -0700
          Re: Is it -2ROT or 2-ROT ? Julian Fondren <julian.fondren@gmail.com> - 2017-05-14 22:17 -0700
            Re: Is it -2ROT or 2-ROT ? Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2017-05-15 17:57 -0400
              Re: Is it -2ROT or 2-ROT ? Julian Fondren <julian.fondren@gmail.com> - 2017-05-15 15:49 -0700
              Re: Is it -2ROT or 2-ROT ? rickman <gnuarm@gmail.com> - 2017-05-16 02:16 -0400
                Re: Is it -2ROT or 2-ROT ? Joel Rees <joel.rees@gmail.com> - 2017-05-16 19:54 -0700
                  Re: Is it -2ROT or 2-ROT ? Lars Brinkhoff <lars.spam@nocrew.org> - 2017-05-17 08:11 +0200
                    Re: Is it -2ROT or 2-ROT ? stephen@mpeforth.com (Stephen Pelc) - 2017-05-17 11:09 +0000
              Re: Is it -2ROT or 2-ROT ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-05-16 03:53 -0500
          Re: Is it -2ROT or 2-ROT ? rickman <gnuarm@gmail.com> - 2017-05-15 01:21 -0400
            Re: Is it -2ROT or 2-ROT ? Cecil Bayona <cbayona@cbayona.com> - 2017-05-15 00:30 -0500
              Re: Is it -2ROT or 2-ROT ? Julian Fondren <julian.fondren@gmail.com> - 2017-05-14 22:40 -0700
                Re: Is it -2ROT or 2-ROT ? Mark Wills <markwills1970@gmail.com> - 2017-05-15 02:06 -0700
              Re: Is it -2ROT or 2-ROT ? hughaguilar96@gmail.com - 2017-05-15 22:45 -0700
            Re: Is it -2ROT or 2-ROT ? Lars Brinkhoff <lars.spam@nocrew.org> - 2017-05-15 09:05 +0200
              Re: Is it -2ROT or 2-ROT ? Mark Wills <markwills1970@gmail.com> - 2017-05-15 02:11 -0700
            Re: Is it -2ROT or 2-ROT ? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-05-15 09:52 +0000
          Re: Is it -2ROT or 2-ROT ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-05-15 05:48 +0000
            Re: Is it -2ROT or 2-ROT ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-05-15 05:14 -0500
            Re: Is it -2ROT or 2-ROT ? stephen@mpeforth.com (Stephen Pelc) - 2017-05-15 11:40 +0000
          Re: Is it -2ROT or 2-ROT ? Mark Wills <markwills1970@gmail.com> - 2017-05-15 02:03 -0700
          Re: Is it -2ROT or 2-ROT ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-05-15 21:24 +0200
          Re: Is it -2ROT or 2-ROT ? "HAA" <someone@microsoft.com> - 2017-05-16 09:57 +1000
            Re: Is it -2ROT or 2-ROT ? Lars Brinkhoff <lars.spam@nocrew.org> - 2017-05-16 08:09 +0200
              Re: Is it -2ROT or 2-ROT ? "HAA" <someone@microsoft.com> - 2017-05-17 00:54 +1000

Page 2 of 2 — ← Prev page 1 [2]


#59255

FromJulian Fondren <julian.fondren@gmail.com>
Date2017-05-14 22:40 -0700
Message-ID<4f34013e-7175-4fa4-a51c-97f6b0a05feb@googlegroups.com>
In reply to#59253
On Monday, May 15, 2017 at 12:21:58 AM UTC-5, rickman wrote:
> Really?  Top of stack is normally on the right.  ROT moves the TOS to 
> the left, so it is <ROT.

Have you ever said, while writing code, "oh, I need to move the TOS to
the left" ? How do you know to write ROT in those cases instead of DUP
or OVER or 0 or R@ ,which all also move the TOS to the left?

What are you really doing? Isn't it something like this?

  ( c-addr u x ) -ROT EAT-STRING ONLY-THEN-EAT-X

Or something like this?

  ( f d ) ROT IF .D ELSE 2DROP THEN


On Monday, May 15, 2017 at 12:30:11 AM UTC-5, Cecil - k5nwa wrote:
> 
> I have not needed it but many Forth from the old days used to be able to 
> equate two words, not a second word that calls the first. Is that still 
> available, I can't remember how it was done.
> 

http://forth-standard.org/standard/tools/SYNONYM

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


#59273

FromMark Wills <markwills1970@gmail.com>
Date2017-05-15 02:06 -0700
Message-ID<245ed296-895a-44dd-b5db-9ee3b2f36efd@googlegroups.com>
In reply to#59255
On Monday, 15 May 2017 06:40:01 UTC+1, Julian Fondren  wrote:
> On Monday, May 15, 2017 at 12:21:58 AM UTC-5, rickman wrote:
> > Really?  Top of stack is normally on the right.  ROT moves the TOS to 
> > the left, so it is <ROT.
> 
> Have you ever said, while writing code, "oh, I need to move the TOS to
> the left" ? How do you know to write ROT in those cases instead of DUP
> or OVER or 0 or R@ ,which all also move the TOS to the left?
> 
> What are you really doing? Isn't it something like this?
> 
>   ( c-addr u x ) -ROT EAT-STRING ONLY-THEN-EAT-X
> 
> Or something like this?
> 
>   ( f d ) ROT IF .D ELSE 2DROP THEN
> 
> 
> On Monday, May 15, 2017 at 12:30:11 AM UTC-5, Cecil - k5nwa wrote:
> > 
> > I have not needed it but many Forth from the old days used to be able to 
> > equate two words, not a second word that calls the first. Is that still 
> > available, I can't remember how it was done.
> > 
> 
> http://forth-standard.org/standard/tools/SYNONYM

Gobbledy gook. You not helping!

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


#59345

Fromhughaguilar96@gmail.com
Date2017-05-15 22:45 -0700
Message-ID<9de2d58b-5ec8-4069-a82b-c2c50173e0c1@googlegroups.com>
In reply to#59253
On Sunday, May 14, 2017 at 10:30:11 PM UTC-7, Cecil - k5nwa wrote:
> This is Forth you can have it both ways and use the form that make you 
> happy.
> 
> I have not needed it but many Forth from the old days used to be able to 
> equate two words, not a second word that calls the first. Is that still 
> available, I can't remember how it was done.

I have SYNONYM FAST-SYNONYM and ALIAS written in ANS-Forth.

Note that Stephen Pelc says this is impossible:

On Thursday, April 2, 2015 at 11:42:55 PM UTC-7, Stephen Pelc wrote:
> On Thu, 2 Apr 2015 19:18:04 -0700 (PDT), hughaguilar96@gmail.com
> wrote:
> >This is not ANS-Forth code --- I don't want to RTFM because I don't want to
> > become an expert on VFX --- I'm already an expert on ANS-Forth.
>
> You asked a tech-support question about VFX. I answered it pointing
> out that your initial assumption (how IF works) was wrong.
>
> The code illustrates precisely why SYNONYM is defined the way it is
> defined - because it requires carnal knowledge. If you want to know
> how SYNONYM works:
>   "So how do you write SYNONYM so that it can make a synonym of an
>   immediate word?"
> then do not complain when you are told.
>
> Stephen

Actually, this is not true. Given the disambiguifiers, it is possible to write SYNONYM FAST-SYNONYM and ALIAS in ANS-Forth. I really consider the disambiguifiers to be the heart and soul of ANS-Forth --- nobody can call themselves an ANS-Forth programmer if they don't have disambiguifiers --- novices should learn how the disambiguifiers work on their first day, because otherwise they will never be ANS-Forth programmers at all.

Also, my assumption about IF was that it was immediate. This is sometimes right (SwiftForth) and sometimes wrong (VFX). The ambiguity of ANS-Forth, however, is meta-wrong --- the disambiguifiers fix this problem --- IF etc. become immediate in all ANS-Forth system (both SwiftForth and VFX) just like they should be (common practice going back to the 1970s).

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


#59264

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2017-05-15 09:05 +0200
Message-ID<86bmqu61mf.fsf@molnjunk.nocrew.org>
In reply to#59252
rickman wrote:
> Really?  Top of stack is normally on the right.  ROT moves the TOS to
> the left, so it is <ROT.  Is that not pretty clear and consistent with
> other notations such as the stack comment on word definitions?

I was thinking the exact opposite.  ROT moves the third stack item to
the right, so it's ROT>.

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


#59274

FromMark Wills <markwills1970@gmail.com>
Date2017-05-15 02:11 -0700
Message-ID<6e2f8148-de25-43c3-a605-bd943c780333@googlegroups.com>
In reply to#59264
On Monday, 15 May 2017 08:05:46 UTC+1, Lars Brinkhoff  wrote:
> rickman wrote:
> > Really?  Top of stack is normally on the right.  ROT moves the TOS to
> > the left, so it is <ROT.  Is that not pretty clear and consistent with
> > other notations such as the stack comment on word definitions?
> 
> I was thinking the exact opposite.  ROT moves the third stack item to
> the right, so it's ROT>.

Nooooo!

1 2 3 ROT> .S
3 1 2 ok

:-)

At least, that's the picture I have in my head. 

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


#59283

From"Rudy Velthuis" <newsgroups@rvelthuis.de>
Date2017-05-15 09:52 +0000
Message-ID<xn0kq0ae25w93hk001@nntp.aioe.org>
In reply to#59252
rickman wrote:

> On 5/15/2017 12:42 AM, Paul Rubin wrote:
> >rickman <gnuarm@gmail.com> writes:
> >>As long as <ROT and ROT> aren't presently used for anything,...
> > > I truly can't believe anyone would give a hoot about one extra
> > > character to type.  It's more an issue of why bother thinking
> > > about it?
> > 
> > It's not the extra character, it's that I can never remember which
> > direction is ROT and which is -ROT, and I suspect it's the same for
> > (some) other users too.  But it's not worth making a change this
> > late in the game.
> 
> Really?  Top of stack is normally on the right.  ROT moves the TOS to
> the left, so it is <ROT.  Is that not pretty clear and consistent
> with other notations such as the stack comment on word definitions?

Yes, it is. I fully agree. 

-- 
Rudy Velthuis        http://www.rvelthuis.de

"Some tortures are physical
 And some are mental,
 But the one that is both
 Is dental."
 -- Ogden Nash

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


#59261

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2017-05-15 05:48 +0000
Message-ID<2017May15.074817@mips.complang.tuwien.ac.at>
In reply to#59245
Paul Rubin <no.email@nospam.invalid> writes:
>I can never remember which
>direction is ROT and which is -ROT, and I suspect it's the same for
>(some) other users too.

All core stack manipulation in Forth is about getting something to the
TOS.  So ROT removes the third element and puts it on the TOS.

Interestingly, in the JVM the TUCK-like words that save a copy of the
TOS further down for later use are more prominent.

So the idea in Forth is that you have some data X lying around,
compute something else (Y), and then use SWAP or ROT or OVER to do
further things with X.

In contrast, in the JVM the idea is that you compute something (Z),
and continue the computation, but if you know that you need Z again,
you stash it away further down the stack.

I wonder if this is just a difference in style, or is related to the
fact that in Forth traditionally more data is kept on the stack, while
in the JVM more things are done with locals.

- 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 2017: http://www.euroforth.org/ef17/

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


#59286

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2017-05-15 05:14 -0500
Message-ID<S-SdnRCzocHn4oTEnZ2dnUU7-XvNnZ2d@supernews.com>
In reply to#59261
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
> All core stack manipulation in Forth is about getting something to the
> TOS.  So ROT removes the third element and puts it on the TOS.
> 
> Interestingly, in the JVM the TUCK-like words that save a copy of the
> TOS further down for later use are more prominent.
> 
> So the idea in Forth is that you have some data X lying around,
> compute something else (Y), and then use SWAP or ROT or OVER to do
> further things with X.
> 
> In contrast, in the JVM the idea is that you compute something (Z),
> and continue the computation, but if you know that you need Z again,
> you stash it away further down the stack.
> 
> I wonder if this is just a difference in style, or is related to the
> fact that in Forth traditionally more data is kept on the stack, while
> in the JVM more things are done with locals.

The TUCK-like words are used in specific patterns.  For example,
dup2_x1 takes the top one or two stack values and tucks them two or
three values down.  dup2_x1 is used by post-incrememnt: we need to
increment a variable and keep its previous value for use in an
expression.

    long j;

    long prank() {
        return j++;
    }

generates

  long prank();
    Code:
       0: aload_0     // "this" pointer
       1: dup
       2: getfield j  // this j(hi) j(lo)
       5: dup2_x1     // j(hi) j(lo) this j(hi) j(lo)
       6: lconst_1
       7: ladd        // j(hi) j(lo) this j+1(lo) j+1(hi)
       8: putfield j
      11: lreturn     // j(hi) j(lo)

Some of the other such words don't seem to be used by anything
today. I don't know what they were ever used for.

Andrew.

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


#59295

Fromstephen@mpeforth.com (Stephen Pelc)
Date2017-05-15 11:40 +0000
Message-ID<5919921e.429019691@news.eternal-september.org>
In reply to#59261
On Mon, 15 May 2017 05:48:17 GMT, anton@mips.complang.tuwien.ac.at
(Anton Ertl) wrote:

>All core stack manipulation in Forth is about getting something to the
>TOS.  So ROT removes the third element and puts it on the TOS.
>
>Interestingly, in the JVM the TUCK-like words that save a copy of the
>TOS further down for later use are more prominent.
>
>So the idea in Forth is that you have some data X lying around,
>compute something else (Y), and then use SWAP or ROT or OVER to do
>further things with X.
>
>In contrast, in the JVM the idea is that you compute something (Z),
>and continue the computation, but if you know that you need Z again,
>you stash it away further down the stack.
>
>I wonder if this is just a difference in style, or is related to the
>fact that in Forth traditionally more data is kept on the stack, while
>in the JVM more things are done with locals.

Chris Bailey did a lot of work on Forth machines. The UFO project
(Ubiquitous Forth Object) focused on a stack machine that could run
Pasgol lanhuages well. It was found that these languages required
deeper stack access than Forth. A couple of address registers helped
too.

Stephen

-- 
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads

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


#59272

FromMark Wills <markwills1970@gmail.com>
Date2017-05-15 02:03 -0700
Message-ID<a43d57a0-5b1d-4e0c-adb1-9c8ee9da34e2@googlegroups.com>
In reply to#59245
On Monday, 15 May 2017 05:42:57 UTC+1, Paul Rubin  wrote:
> It's not the extra character, it's that I can never remember which
> direction is ROT and which is -ROT, and I suspect it's the same for
> (some) other users too.  But it's not worth making a change this late in
> the game.

EXAAAAAAACTLY!

Every fricken time I need to use them I need to do a quick:

1 2 3 rot .s

To see which one moves the way I want it to!

<ROT and ROT> would have been SO much better!

I feel a couple of synonyms coming on!

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


#59322

Fromalbert@cherry.spenarnc.xs4all.nl (Albert van der Horst)
Date2017-05-15 21:24 +0200
Message-ID<ofcvaa$af4$1@cherry.spenarnc.xs4all.nl>
In reply to#59245
In article <87shk6afxs.fsf@nightsong.com>,
Paul Rubin  <no.email@nospam.invalid> wrote:
>rickman <gnuarm@gmail.com> writes:
>> As long as <ROT and ROT> aren't presently used for anything,...
>> I truly can't believe anyone would give a hoot about one extra
>> character to type.  It's more an issue of why bother thinking about
>> it?
>
>It's not the extra character, it's that I can never remember which
>direction is ROT and which is -ROT, and I suspect it's the same for
>(some) other users too.  But it's not worth making a change this late in
>the game.

That is why when I need ROT for swapping an item and a string I start the file
with
    'ROT ALIAS SDSWAP
or
    : DSSWAP ROT ROT ;

(I don't have -ROT in ciforth.)

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


#59338

From"HAA" <someone@microsoft.com>
Date2017-05-16 09:57 +1000
Message-ID<ofdf8s$3pa$1@gioia.aioe.org>
In reply to#59245
Paul Rubin wrote:
> rickman <gnuarm@gmail.com> writes:
> > As long as <ROT and ROT> aren't presently used for anything,...
> > I truly can't believe anyone would give a hoot about one extra
> > character to type.  It's more an issue of why bother thinking about
> > it?
>
> It's not the extra character, it's that I can never remember which
> direction is ROT and which is -ROT, and I suspect it's the same for
> (some) other users too.  But it's not worth making a change this late in
> the game.

Given Forth deals with items that are on *top* of the stack, that's going
to be predominant purpose and direction of stack jugglers.  OVER SWAP
ROT DUP ROLL PICK etc all serve to bring items to the top of the stack
where the action is.  Less used and typically *not* in the Standard are
functions that do the reverse, namely move items *away* from the top
of the stack.  Hence the '-' prefix suggesting that ideally you should 'not'
have to use this word.


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


#59346

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2017-05-16 08:09 +0200
Message-ID<86inl149ko.fsf@molnjunk.nocrew.org>
In reply to#59338
HAA wrote:
> Given Forth deals with items that are on *top* of the stack, that's
> going to be predominant purpose and direction of stack jugglers.  OVER
> SWAP ROT DUP ROLL PICK etc all serve to bring items to the top of the
> stack where the action is.  Less used and typically *not* in the
> Standard are functions that do the reverse, namely move items *away*
> from the top of the stack.

So which are these lesser juggling words?  I suppose TUCK and -ROT are
the prime examples.  DROP and >R also move things away from the top, but
a case could be made either way if you're inclined to argue about it.
Of these, only -ROT is not in the standard.

Any others?

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


#59375

From"HAA" <someone@microsoft.com>
Date2017-05-17 00:54 +1000
Message-ID<off3r5$ji9$1@gioia.aioe.org>
In reply to#59346
Lars Brinkhoff wrote:
> HAA wrote:
> > Given Forth deals with items that are on *top* of the stack, that's
> > going to be predominant purpose and direction of stack jugglers.  OVER
> > SWAP ROT DUP ROLL PICK etc all serve to bring items to the top of the
> > stack where the action is.  Less used and typically *not* in the
> > Standard are functions that do the reverse, namely move items *away*
> > from the top of the stack.
>
> So which are these lesser juggling words?  I suppose TUCK and -ROT are
> the prime examples.  DROP and >R also move things away from the top, but
> a case could be made either way if you're inclined to argue about it.
> Of these, only -ROT is not in the standard.
>
> Any others?

I have -ROLL mainly because the system needs it for a task.  There's
not a lot.  DROP is bringing NOS to TOS.  TUCK is making a copy.
>R R> always work in pairs so it makes sense to indicate that.



[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

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


csiph-web