+R as a name for DUP >R 
Author Message
 +R as a name for DUP >R

Background
----------

All we know that DUP >R should be a single word, and on many systems
it is: DUP>R . But I myself, as, probably, other people, dislike this
name because of the following reasons:

1. Its name is not a glyph for what it does, it describes what it is
equivalent to.

2. The name is long and cumbersome

3. Its double-cell analog would be confusing: 2DUP>R is not the
same as 2DUP >R . 2DUP2>R "too-dupe-too-too-ar" ? Terrific.

4. There is no DUP and no >R inside DUP>R; instead, >R is DUP>R DROP .

5. All return stack access operators consist of R and one special
symbol. DUP>R does not.

An alternative, that has BTW been a proposal for standardization,

and the proposal has not passed.

One more alternative is COPY>R . This is what I currently use.
I dislike it because nobody else uses it, and because of 2. and 5.

Requirements
-------------

The name must be short, and must look almost like >R .
When used along with >R R>'s, it must be clear that it also
is a return stack access operator.

To show how it looks, I will use the following phrase:

  swap >r copy>r um* 0 r> r> um* d+



are [probably] already in use as an operator that fetches a cell
or a string from the address found at the return stack top,
IIRC, also incrementing it.

The names *R -R =R look almost like >R.

  swap >r *r um* 0 r> r> um* d+

No, * does not look as a movement operator (although so it is in C)

  swap >r -r um* 0 r> r> um* d+

Looks better: >R is one abbreviation from ->R , and -R is another
possible abbreviation. But the minus is still confusing. We add
an item to the return stack.

Maybe, we shall convert the arrow ">" to "="?
But "=" does not look like a movement operator either:

  swap >r =r um* 0 r> r> um* d+

I prefer + :

  swap >r +r um* 0 r> r> um* d+

Finally, we add an item onto the return stack.

Proposal
--------

+R ( x -- x ) ( r: -- x ) "plus-r"

place a copy of the data stack top onto the return stack.

The name looks a bit unusual at the 1st sight, but so is >R ,
where ">" does not mean "greater than".
">" represents an arrow: we move an item onto the data stack
(add there and remove here).
In the case of "+", we add an item onto the return stack
without removing it.

The double-cell analog is:

2+R ( x1 x2 -- x1 x2 ) ( r: -- x1 x2 ) "two-plus-r"

place copies of the data stack top two items onto the return stack.

Examples from real code
-----------------------

Let us see how +R looks in the code compared to DUP>R / COPY>R .

: NewStruct ( n1 --- hstruct )    dup>r malloc dup r> erase ;

: NewStruct ( n1 --- hstruct )    +r malloc dup r> erase ;

\ ---

: #WORDLIST     ( #threads -- wid )
                1 MAX 511 MIN DUP , VOC-LINK LINK,
                HERE DUP>R OVER CELLS ALLOT
                           SWAP CELLS ERASE R> ;

: #WORDLIST     ( #threads -- wid )
                1 MAX 511 MIN DUP , VOC-LINK LINK,
                HERE +R OVER CELLS ALLOT
                        SWAP CELLS ERASE R> ;
\ ---

: CS-PICK       ( dest .. u -- dest )   \ pick both addr and ?pairs value
                2* 1+ COPY>R PICK R> PICK ;

: CS-PICK       ( dest .. u -- dest )   \ pick both addr and ?pairs value
                2* 1+ +R PICK R> PICK ;

\ ---

: UT*   ( ulo uhi u -- utlo utmid uthi )
        swap >r copy>r
        um* 0 r> r> um* d+ ;
: UT*   ( ulo uhi u -- utlo utmid uthi )
        swap >r +r
        um* 0 r> r> um* d+ ;
\ ---
: UT/   ( utlo utmid uthi n -- d1 )
        copy>r um/mod -rot r> um/mod
        nip swap ;
: UT/   ( utlo utmid uthi n -- d1 )
        +r um/mod -rot r> um/mod
        nip swap ;

\ ===
\ this is from a debugging tool
\ 2* DROP sets carry
\ [asm src asm] is Shift Right via Carry (carry goes to MSB)
: save-state ( -- )
        0 [asm src asm] +R 2* DROP ( save carry )
        >R >R >R >R >R +R
        [asm mova c asm] +R
        [asm mova a2 asm] +R
        [asm mova a1 asm] +R
        [asm mova 0 src asm] +R
[snip]
;
: save-state ( -- )
        0 [asm src asm] DUP>R 2* DROP ( save carry )
        >R >R >R >R >R DUP>R
        [asm mova c asm] DUP>R
        [asm mova a2 asm] DUP>R
        [asm mova a1 asm] DUP>R
        [asm mova 0 src asm] DUP>R
[snip]
;



Sat, 21 May 2005 17:55:11 GMT  
 +R as a name for DUP >R

Quote:

> An alternative, that has BTW been a proposal for standardization,

> and the proposal has not passed.

> One more alternative is COPY>R . This is what I currently use.
> I dislike it because nobody else uses it, and because of 2. and 5.

> Requirements
> -------------

> The name must be short, and must look almost like >R .

I use ">RR" which was named after the single operations ">r r".
which, is short and looks almost like >r :)

I use "+r" (or "r+") as a compiler word for
        " r> dup 1 cells + >r"

Quote:

> I prefer + :

objection: "+r" suggest some addition which it doesn't.

best,
        hp

--
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml en/de



Sat, 21 May 2005 19:07:15 GMT  
 +R as a name for DUP >R


<snipped>

Quote:

>Background
>----------

>All we know that DUP >R should be a single word, and on many systems
>it is: DUP>R . But I myself, as, probably, other people, dislike this
>name because of the following reasons:

>1. Its name is not a glyph for what it does, it describes what it is
>equivalent to.

In my case, it describes exactly what it does.

Quote:

>2. The name is long and cumbersome


data stack size isn't increased transiently.  This just *might* cause an
unnecessary spill to memory in a stack machine.

Quote:

>3. Its double-cell analog would be confusing: 2DUP>R is not the
>same as 2DUP >R . 2DUP2>R "too-dupe-too-too-ar" ? Terrific.

>4. There is no DUP and no >R inside DUP>R; instead, >R is DUP>R DROP .

This seems to be specific to a particular processor which shouldn't IMO

needed.

Cheers
--
Keith Wootten



Sat, 21 May 2005 19:47:45 GMT  
 +R as a name for DUP >R

Quote:


> > An alternative, that has BTW been a proposal for standardization,

> > and the proposal has not passed.

> > One more alternative is COPY>R . This is what I currently use.
> > I dislike it because nobody else uses it, and because of 2. and 5.

> > Requirements
> > -------------

> > The name must be short, and must look almost like >R .

> I use ">RR" which was named after the single operations ">r r".
> which, is short and looks almost like >r :)

I use >RR on systems like Win32Forth and F-PC to work with
return addresses. For example, on Win32Forth >RR is REL>ABS >R .

Quote:

> I use "+r" (or "r+") as a compiler word for
>         " r> dup 1 cells + >r"

Use of this name could be an objection, but I am not sure now.
I always thought that this thing (fetch and post-increment)

Are you sure that you use +r for a fetch with post-increment?

Quote:

> > I prefer + :

> objection: "+r" suggest some addition which it doesn't.

It is not an objection.

What about STRING+ ? Concatenation is not addition either,
but addition of an item onto the stack *is* concatenation.

In addition, + means addition when it is postfix ( D+ UM+ F+ C+! ).
In +R it is prefix.

BTW, > also means "greater than", but Forth uses it as an arrow,
and HTML uses it as a bracket.



Sat, 21 May 2005 19:14:06 GMT  
 +R as a name for DUP >R

Quote:

> >4. There is no DUP and no >R inside DUP>R; instead, >R is DUP>R DROP .

> This seems to be specific to a particular processor

No. So it is on 80x86

CODE >R         ( n1 -- )       \ push n1 onto the return stack

                mov     -4 [ebp], ebx
                sub     ebp, # 4
                pop     ebx
                exec
c;
CODE COPY>R     ( n1 -- n1 )    \ push a copy of n1 onto the return stack

                mov     -4 [ebp], ebx
                sub     ebp, # 4
                exec
c;
CODE DROP       ( n -- )        \ discard top entry on data stack

                pop     ebx
                exec
c;

so it is on the TF2216 stack processor:

MACRO >R     rpush [ss]      mova n pop              END-MACRO
MACRO +R        rpush [ss]      END-MACRO
MACRO DROP      mova n pop      END-MACRO
( TF2216 has stacks in memory)

and so it will be on any processor that cannot move from one stack
to another in a single instruction.



Sat, 21 May 2005 19:27:19 GMT  
 +R as a name for DUP >R

Quote:

> ...
> CODE COPY>R     ( n1 -- n1 )    \ push a copy of n1 onto the return stack

COPU>R is an ok name if you have to have one, but I'd really vote against
any such addition.  I don't think it saves enough or is used enough to
justify
having an extra word, and optimizing compilers, which are increasingly
popular,
will optimize it anyway.

Cheers,
Elizabeth



Sat, 21 May 2005 23:25:14 GMT  
 +R as a name for DUP >R

Quote:

> Background
> ----------
> All we know that DUP >R should be a single word, and on many systems
> it is: DUP>R .

Not really, no.  It's a bad word for the classic reason that words
should consume their arguments.

If this is so very important, it seems to make more sense to have a
smart compiler than to define a new word in this way.

Andrew.



Sun, 22 May 2005 03:22:25 GMT  
 +R as a name for DUP >R

Quote:

> Background
> ----------

> All we know that DUP >R should be a single word, and on many systems
> it is: DUP>R . But I myself, as, probably, other people, dislike this
> name because of the following reasons:

This Newbie could go for:


in spite of the fact there are two operators (nonalphanumeric) with the R.

I don't know if the following exist, but I could go for;


to do a store and keep a copy of the value on the stack ( over swap ! )

Actually, =! could be sufficient ( for  =>! ).



Rufus



Sun, 22 May 2005 02:58:52 GMT  
 +R as a name for DUP >R

Quote:
> I don't know if the following exist, but I could go for;





make much sense to fetch and store something without modifying it, it
must mean "update" :-)


as standard words. And I would avoid defining the double cell
equivalent, I don't think it is used that often.

Greetings,
  Jorge



Sun, 22 May 2005 03:52:16 GMT  
 +R as a name for DUP >R

Quote:

> 3. Its double-cell analog would be confusing: 2DUP>R is not the
> same as 2DUP >R . 2DUP2>R "too-dupe-too-too-ar" ? Terrific.

2dup>r is always 2dup 2>r - there is no "mixed" operation, same
target type is the default if not otherwise noted (M or T). If
it starts out with 2dup it will follow into 2>r. The sound of
2>r "too-too-ar" is there anyway in the word named 2>r, and
unless one opposes that one, the argument is shallow.

the "+" is clearly offworld...



Sun, 22 May 2005 05:33:33 GMT  
 +R as a name for DUP >R

Quote:



>> > An alternative, that has BTW been a proposal for standardization,

>> > and the proposal has not passed.

>> > One more alternative is COPY>R . This is what I currently use.
>> > I dislike it because nobody else uses it, and because of 2. and 5.

>> > Requirements
>> > -------------

>> > The name must be short, and must look almost like >R .

>> I use ">RR" which was named after the single operations ">r r".
>> which, is short and looks almost like >r :)

> I use >RR on systems like Win32Forth and F-PC to work with
> return addresses. For example, on Win32Forth >RR is REL>ABS >R .

but this is certainly higly specific, to a particular system as well as to
personal habits. I don't think that anyone could deduce that meaning from
your abreviation.

Quote:

>> I use "+r" (or "r+") as a compiler word for
>>         " r> dup 1 cells + >r"

> Use of this name could be an objection, but I am not sure now.
> I always thought that this thing (fetch and post-increment)

> Are you sure that you use +r for a fetch with post-increment?

no, not really:) indeed,  I use "R+"
Only at a certain occasion which was very specific, "+R" did something

I simply tried to point to the fact(?) that a "+" in a name suggests some
addition, whether arithmetically or (quasi-)substancially, i.e. 'append'.
my interpretation, though, not an absolute measure...

Quote:

>> > I prefer + :

>> objection: "+r" suggest some addition which it doesn't.

> It is not an objection.

> What about STRING+ ? Concatenation is not addition either,
> but addition of an item onto the stack *is* concatenation.

right. there is a difference between absolute correctness (which won't
exist, almost at all) and something 'reasonable' , much related to personal
habit, interpretation, understanding, education...

anyway,  the rest after my ">R R" example were mere thoughts, why or why
not this 'word' may be plausible or not. for me, ">RR" simply invented
itself from textual concatenation of the two operations.

Quote:

> In addition, + means addition when it is postfix ( D+ UM+ F+ C+! ).
> In +R it is prefix.

> BTW, > also means "greater than", but Forth uses it as an arrow,

                ^^^^^^^^^

Quote:
> and HTML uses it as a bracket.

that sort of statements highly depend on context,  as well as the above
"+"-es &c. computer-'languages' are -imho- not the measure when asking for
reasonability of a (somewat) lingustic construct - it's the opposite way.

best
        hp
---
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml en/de
---



Sun, 22 May 2005 16:10:38 GMT  
 +R as a name for DUP >R

Quote:

> > ...
> > CODE COPY>R     ( n1 -- n1 )    \ push a copy of n1 onto the return stack

> COPU>R is an ok name if you have to have one, but I'd really vote against
> any such addition.  I don't think it saves enough or is used enough to
> justify
> having an extra word, and optimizing compilers, which are increasingly
> popular,
> will optimize it anyway.

Just for kicks, I tried this to see what VFX optimizes out. I put in
my own comments:


drop ;  ok
see mytype

Quote:
>R

( 0049905C    53 )                    PUSH    EBX
( 0049905D    8B5D00 )                MOV     EBX, [EBP]
( 00499060    8D6D04 )                LEA     EBP, [EBP+04]
BEGIN
( 00499063    8B1424 )                MOV     EDX, [ESP]

( 00499068    0F8418000000 )          JZ/E    00499086
COUNT
( 0049906E    8BD3 )                  MOV     EDX, EBX
( 00499070    43 )                    INC     EBX
( 00499071    0FB612 )                MOVZX   EDX, Byte Ptr 0 [EDX]
( 00499074    8D6DFC )                LEA     EBP, [EBP+-04]
( 00499077    895D00 )                MOV     [EBP], EBX
( 0049907A    8BDA )                  MOV     EBX, EDX
EMIT
( 0049907C    E8D3C7F6FF )            CALL    00405854  EMIT
R> 1- >R
( 00499081    5A )                    POP     EDX
( 00499082    4A )                    DEC     EDX
( 00499083    52 )                    PUSH    EDX
REPEAT
( 00499084    EBDD )                  JMP     00499063
R> DROP
( 00499086    8D642404 )              LEA     ESP, [ESP+04]
;
( 0049908A    C3 )                    NEXT,

VFX optimizes R> DROP and R> 1- >R nicely. In each case, the short
code sequence is shorter and faster than a call to an equivalent word.

A compiler doesn't have to be very smart to optimize DUP >R or R>
DROP. R> 1- >R takes a little more sophistication. You might look for
that one if you're shopping around for a Forth.



Mon, 23 May 2005 07:13:28 GMT  
 +R as a name for DUP >R

Quote:

> A compiler doesn't have to be very smart to optimize DUP >R or R>
> DROP. R> 1- >R takes a little more sophistication. You might look for
> that one if you're shopping around for a Forth.

Optimize  UNDER+  from Thinking Forth.


Mon, 23 May 2005 07:50:18 GMT  
 +R as a name for DUP >R

Quote:


> > 3. Its double-cell analog would be confusing: 2DUP>R is not the
> > same as 2DUP >R . 2DUP2>R "too-dupe-too-too-ar" ? Terrific.

> 2dup>r is always 2dup 2>r - there is no "mixed" operation, same
> target type is the default if not otherwise noted (M or T). If
> it starts out with 2dup it will follow into 2>r. The sound of
> 2>r "too-too-ar" is there anyway in the word named 2>r, and
> unless one opposes that one, the argument is shallow.

> the "+" is clearly offworld...

Agreed.

What is the description of the function we are trying to name?  How
about:

    Copy the top of the data stack above the return stack.

All of the do-it-my-way reports have been bad.

How bad?

1.  The function doesn't need a name.  The best way to express the

and within the second expression.  When a pauper programmer must use
twentieth century development software, every additional definition
is profligate.

2.  Extra definitions decrease portability and comprehension.

3.  The given pronunciations are bad.  The pronunciations in the
Standard are bad - they are not pronunciation, but spelling.  People
do not tee-ay-ell-kay like tee-aitch-ay-tee. In particular, the
pronunciation should be an acronym, an apocope, in rare cases an
initialization, but usually spoken in full.  Care should be taken to
distinguish between 322 and 3>2, etc.  Say what the word does, not
cryptography for it.

  Thus for me:

  3>R2 is 3onto the return stack2 or 3onto the rack2.

  32>R" is 3pair onto the return stack2 or "pair onto the rack2.

  32 >R2 is 3two onto _etc_2.

4.  When developing applications for embedded systems, or writing
personal programs, I want at least a contemporary laptop (which is
what I use).  Bare minimal optimization should optimize 3DUP >R2,
3ROT ROT2, 3R> DROP2, 30= IF2, 3DUP IF DROP", etc.  If the target
doesn't do this, my code works without change on the target, and
works better without change on my personal machine.

With programming, as with coffee, I am a snob.  I seldom tolerate
less than best.  I am not an elitist snob, where I would _never_
tolerate less than best.

--
Wil Baden
Neil Bawd



Mon, 23 May 2005 07:53:26 GMT  
 +R as a name for DUP >R

Quote:




>>>3. Its double-cell analog would be confusing: 2DUP>R is not the
>>>same as 2DUP >R . 2DUP2>R "too-dupe-too-too-ar" ? Terrific.

>>2dup>r is always 2dup 2>r - there is no "mixed" operation, same
>>target type is the default if not otherwise noted (M or T). If
>>it starts out with 2dup it will follow into 2>r. The sound of
>>2>r "too-too-ar" is there anyway in the word named 2>r, and
>>unless one opposes that one, the argument is shallow.

>>the "+" is clearly offworld...

> Agreed.

> What is the description of the function we are trying to name?  How
> about:

>     Copy the top of the data stack above the return stack.

> All of the do-it-my-way reports have been bad.

> How bad?

> 1.  The function doesn't need a name.  The best way to express the

> and within the second expression.  When a pauper programmer must use
> twentieth century development software, every additional definition
> is profligate.

> 2.  Extra definitions decrease portability and comprehension.

> 3.  The given pronunciations are bad.  The pronunciations in the
> Standard are bad - they are not pronunciation, but spelling.  People
> do not tee-ay-ell-kay like tee-aitch-ay-tee. In particular, the
> pronunciation should be an acronym, an apocope, in rare cases an
> initialization, but usually spoken in full.  Care should be taken to
> distinguish between 322 and 3>2, etc.  Say what the word does, not
> cryptography for it.

>   Thus for me:

>   3>R2 is 3onto the return stack2 or 3onto the rack2.

>   32>R" is 3pair onto the return stack2 or "pair onto the rack2.

>   32 >R2 is 3two onto _etc_2.

> 4.  When developing applications for embedded systems, or writing
> personal programs, I want at least a contemporary laptop (which is
> what I use).  Bare minimal optimization should optimize 3DUP >R2,
> 3ROT ROT2, 3R> DROP2, 30= IF2, 3DUP IF DROP", etc.  If the target
> doesn't do this, my code works without change on the target, and
> works better without change on my personal machine.

> With programming, as with coffee, I am a snob.  I seldom tolerate
> less than best.  I am not an elitist snob, where I would _never_
> tolerate less than best.

Wil, let's express it shorter: combination words are not needed
for portable programs since they can use the uncombined ones in
a sequence.

To summarize the news thread a bit: makers/users of optimizing
compilers will say that it is not needed since their compilers
has extra code for recognizing the two words, other users want
the word to exist since the want to use that extra code to get
a bit of speed as well. Both is not the primary target of
specification making targetted at portable programming.

What's left is just how the thing evolved - to have a look what
people use when they make it as an extra word, and here we are
with different opinions. Nobody has to like such opinioning ;-)



Mon, 23 May 2005 08:27:54 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. HELP>>>DUP SYMBOL PROBLEM

2. DUP >R

3. Collection>>flatten - looking for a better name

4. >>>ARGHH>>>got 2-100,one line email names,which way to produce a 3rd list of Uniq, diff or awk-sed

5. HELP>>>>>>>Fortran-Pascal Linking

6. >>>>>>>FROM SMTK TO C++

7. ><><><><>Heeeeeeeeeeeeeeelp on INT 14!><><><><><>

8. <<<<<YOU MUST CHECK THIS OUT >>>>>>>>>> 2103

9. >>>>>AVL tree

10. >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||

11. ANNOUNCE>>>>>TOTAL FrameWork from Cincom

12. Functions>>Data Acquisition>>DAQ Channel name constant... what does it do?

 

 
Powered by phpBB® Forum Software