<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Using R@</title><link>https://sourceforge.net/p/forth-4th/wiki/Using%2520R%2540/</link><description>Recent changes to Using R@</description><atom:link href="https://sourceforge.net/p/forth-4th/wiki/Using%20R@/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 30 Mar 2022 12:47:17 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/forth-4th/wiki/Using%20R@/feed" rel="self" type="application/rss+xml"/><item><title>Using R@ modified by thebeez</title><link>https://sourceforge.net/p/forth-4th/wiki/Using%2520R%2540/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">thebeez</dc:creator><pubDate>Wed, 30 Mar 2022 12:47:17 -0000</pubDate><guid>https://sourceforge.net5278e5b563912cc1c4fa0e7efbddcb70add2d75b</guid></item><item><title>Using R@ modified by thebeez</title><link>https://sourceforge.net/p/forth-4th/wiki/Using%2520R%2540/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v4
+++ v5
@@ -1,6 +1,6 @@
 I first encountered this technique when I was studying the FIG-Editor. The author explained how he used *TORS* (Top OF Return Stack) as a kind of "read-only" local variable. You can put an address, limit or other constant there and retrieve it with a single **R@**.

-In the years to follow I've used this technique a lot of times. One of the best pieces of Forth advise I ever got. When the [The 4tH preprocessor] came to be, it only had four "registers". I added the string stack much later on. Still, having four variables at your fingertips was quite handy.
+In the years to follow I've used this technique a lot of times. One of the best pieces of Forth advise I ever got. When [The 4tH preprocessor] came to be, it only had four "registers". I added the string stack much later on. Still, having four variables at your fingertips was quite handy.

 So, just before the release of  v3.62.5 I got an idea. Yes, we had **R@**. In the meanwhile I had added **R'@** as an "inline macro" - not as a primitive. And sometimes I was in trouble and "abused" **J** to retrieve the third item from the return stack. Everything was in place - except for the vision.

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">thebeez</dc:creator><pubDate>Mon, 17 Jul 2017 21:04:08 -0000</pubDate><guid>https://sourceforge.net83783e463d24885cf8e2377738c1f85ceac62925</guid></item><item><title>Using R@ modified by thebeez</title><link>https://sourceforge.net/p/forth-4th/wiki/Using%2520R%2540/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v3
+++ v4
@@ -1,6 +1,6 @@
 I first encountered this technique when I was studying the FIG-Editor. The author explained how he used *TORS* (Top OF Return Stack) as a kind of "read-only" local variable. You can put an address, limit or other constant there and retrieve it with a single **R@**.

-In the years to follow I've used this technique a lot of times. One of the best pieces of Forth advise I ever got. When the [the 4tH preprocessor] came to be, it only had four "registers". I added the string stack much later on. Still, having four variables at your fingertips was quite handy.
+In the years to follow I've used this technique a lot of times. One of the best pieces of Forth advise I ever got. When the [The 4tH preprocessor] came to be, it only had four "registers". I added the string stack much later on. Still, having four variables at your fingertips was quite handy.

 So, just before the release of  v3.62.5 I got an idea. Yes, we had **R@**. In the meanwhile I had added **R'@** as an "inline macro" - not as a primitive. And sometimes I was in trouble and "abused" **J** to retrieve the third item from the return stack. Everything was in place - except for the vision.

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">thebeez</dc:creator><pubDate>Mon, 17 Jul 2017 21:03:44 -0000</pubDate><guid>https://sourceforge.net9fcc50b4add630aea71dd3dab2feedd97a053a22</guid></item><item><title>Using R@ modified by thebeez</title><link>https://sourceforge.net/p/forth-4th/wiki/Using%2520R%2540/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v2
+++ v3
@@ -1,6 +1,6 @@
 I first encountered this technique when I was studying the FIG-Editor. The author explained how he used *TORS* (Top OF Return Stack) as a kind of "read-only" local variable. You can put an address, limit or other constant there and retrieve it with a single **R@**.

-In the years to follow I've used this technique a lot of times. One of the best pieces of Forth advise I ever got. When the preprocessor came to be, it only had four "registers". I added the string stack much later on. Still, having four variables at your fingertips was quite handy.
+In the years to follow I've used this technique a lot of times. One of the best pieces of Forth advise I ever got. When the [the 4tH preprocessor] came to be, it only had four "registers". I added the string stack much later on. Still, having four variables at your fingertips was quite handy.

 So, just before the release of  v3.62.5 I got an idea. Yes, we had **R@**. In the meanwhile I had added **R'@** as an "inline macro" - not as a primitive. And sometimes I was in trouble and "abused" **J** to retrieve the third item from the return stack. Everything was in place - except for the vision.

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">thebeez</dc:creator><pubDate>Mon, 17 Jul 2017 21:02:50 -0000</pubDate><guid>https://sourceforge.net586ecd3b31a87877eb9bcfee9d4b8771106adaef</guid></item><item><title>Using R@ modified by thebeez</title><link>https://sourceforge.net/p/forth-4th/wiki/Using%2520R%2540/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">thebeez</dc:creator><pubDate>Mon, 17 Jul 2017 20:57:27 -0000</pubDate><guid>https://sourceforge.netbe08232000e34b91e0c96b086ad5b89117c56c82</guid></item><item><title>Using R@ modified by thebeez</title><link>https://sourceforge.net/p/forth-4th/wiki/Using%2520R%2540/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;I first encountered this technique when I was studying the FIG-Editor. The author explained how he used &lt;em&gt;TORS&lt;/em&gt; (Top OF Return Stack) as a kind of "read-only" local variable. You can put an address, limit or other constant there and retrieve it with a single &lt;strong&gt;R@&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In the years to follow I've used this technique a lot of times. One of the best pieces of Forth advise I ever got. When the preprocessor came to be, it only had four "registers". I added the string stack much later on. Still, having four variables at your fingertips was quite handy.&lt;/p&gt;
&lt;p&gt;So, just before the release of  v3.62.5 I got an idea. Yes, we had &lt;strong&gt;R@&lt;/strong&gt;. In the meanwhile I had added &lt;strong&gt;R'@&lt;/strong&gt; as an "inline macro" - not as a primitive. And sometimes I was in trouble and "abused" &lt;strong&gt;J&lt;/strong&gt; to retrieve the third item from the return stack. Everything was in place - except for the vision.&lt;/p&gt;
&lt;p&gt;I decided to turn &lt;strong&gt;R'@&lt;/strong&gt; into a primitive and introduce &lt;strong&gt;R"@&lt;/strong&gt;. I'm not too proud of that name, but it seemed logical to keep up with the convention. Now we had three words that could retrieve &lt;em&gt;TORS&lt;/em&gt;, &lt;em&gt;2ORS&lt;/em&gt; and &lt;em&gt;3ORS&lt;/em&gt;. I had high expectations for these, but at c.l.f. there were people who claimed to have "been there and done that". To no avail, of course.&lt;/p&gt;
&lt;p&gt;But I'm Dutch and hence very stubborn. So I implemented it anyway. While writing code for v3.63.0 I used this new feature. I also learned you could create an alias for &lt;strong&gt;R@&lt;/strong&gt;, &lt;strong&gt;R'@&lt;/strong&gt; and &lt;strong&gt;R"@&lt;/strong&gt; using &lt;strong&gt;AKA&lt;/strong&gt;. Which IMHO makes the code a lot easier to read. This is from a "Midpoint Circle" algorithm:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;aka r@  x0
aka r'@ y0

: circle                               ( x y radius --)
  swap &amp;gt;r swap &amp;gt;r 1 over - swap 0      ( dp x y R: x0 y0)

  begin
    over x0 + over y0 +                set_pixel ( x0 + x, y0 + y)
    over x0 swap - over y0 +           set_pixel ( x0 - x, y0 + y)
    over x0 + over y0 swap -           set_pixel ( x0 + x, y0 - y)
    over x0 swap - over y0 swap -      set_pixel ( x0 - x, y0 - y)
    over y0 + over x0 +           swap set_pixel ( x0 + y, y0 + x)
    over y0 + over x0 swap -      swap set_pixel ( x0 - y, y0 + x)
    over y0 swap - over x0 +      swap set_pixel ( x0 + y, y0 - x)
    over y0 swap - over x0 swap - swap set_pixel ( x0 - y, y0 - x)
                                       ( dp x y R: x0 y0)
    1+ &amp;gt;r over 0&amp;gt; if 1- r@ over - else r@ then 2* 1+ rot + swap r&amp;gt;
    over over &amp;lt;                        ( dp x y f R: x0 y0)
  until drop drop drop r&amp;gt; drop r&amp;gt; drop
;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Note it is still possible to use the return stack in a more traditional way - even if you've &lt;strong&gt;AKA&lt;/strong&gt;'d any of the "return stack fetch" words. You simply use &lt;strong&gt;R@&lt;/strong&gt; to distinguish between them. Of course, you still have to take care - it is &lt;em&gt;still&lt;/em&gt; Forth. Note that it doesn't need to clobber your symboltable - you simply &lt;strong&gt;HIDE&lt;/strong&gt; the aliases when you're done.&lt;/p&gt;
&lt;p&gt;Personally, I think it adds something to the language. Especially when you're juggling with a lot of parameters - yes, you can do clever things in Forth, but some algorithms simply come with a lot of parameters.&lt;/p&gt;
&lt;p&gt;On the other hand, I also understand people who criticize it with the argument "a stack is &lt;em&gt;not&lt;/em&gt; an array". I completely subscribe to that view - that's why I never implemented &lt;strong&gt;PICK&lt;/strong&gt; and &lt;strong&gt;ROLL&lt;/strong&gt; in the core language.&lt;/p&gt;
&lt;p&gt;But there is IMHO a difference between turning the &lt;em&gt;entire&lt;/em&gt; stack into an array or just three elements of it. In essence, this facility has always been there. If you wanted to use it &lt;em&gt;before&lt;/em&gt; these changes, you could. If you don't want to use it now, then don't.&lt;/p&gt;
&lt;p&gt;However, &lt;em&gt;if&lt;/em&gt; you want to use it, it just became a lot easier, more consistent, more compact and much faster.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">thebeez</dc:creator><pubDate>Mon, 17 Jul 2017 20:57:01 -0000</pubDate><guid>https://sourceforge.net0d6c67375f1097d3760ec2a447b72538a012ab9a</guid></item></channel></rss>