Post Reply 
RPL stackrobatics decoder
07-10-2018, 07:17 AM
Post: #4
RE: RPL stackrobatics decoder
(07-09-2018 04:14 PM)Claudio L. Wrote:  Any more rules or suggestions to improve on this?

Not a suggestion but looking at Thomas Okken's program here:
Code:
<< DUP 1 - -> n n1
   << 1 n FOR i i INV NEXT
      n 1 + n n1 + FOR i n1 DUPN i INV NEXT
      n DUP 2 ->LIST ->ARRY
   >>
>>

I wonder how you would ever end up with something like this:
Code:
double[][] hilbert(int n) {
    double[][] h = new double[n][n];
    for (int j = 0; j < n; j++)
        h[0][j] = 1.0 / (j + 1);
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < n - 1; j++)
            h[i][j] = h [i - 1][j + 1];
        h[i][n - 1] = 1.0 / (i  + j + 1);
    }
    return h;
}

Commands like DUPN, ->LIST or ->ARRY consume or produce an arbitrary number of parameters. We know their exact numbers only at runtime.
Thus using local variables like in case of + or MOD wouldn't work.

And then there are idiomatic ways to do something like looping through an array.

C
Code:
const char* name = "Claudio";
size_t length = strlen(name);
for (int i = 0; i < length; i++) {
    printf("%c\n", name[i]);
}

Python
Code:
name = "Claudio"
for c in name:
    print c

Of course we could mimic the same behaviour in Python:
Code:
name = "Claudio"
length = len(name)
for i in range(length):
    print name[i]

But that would not be considered Pythonic.

Thus I'm not sure if it really helps to automatically translate RPL into other languages.
Most probably you end up with something that is not idiomatic and will be hard to understand.

However it could be helpful to automatically create stack-diagrams, e.g. when calculating the complex arccos function.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RPL stackrobatics decoder - Claudio L. - 07-09-2018, 04:14 PM
RE: RPL stackrobatics decoder - Claudio L. - 07-09-2018, 06:12 PM
RE: RPL stackrobatics decoder - Thomas Klemm - 07-10-2018 07:17 AM
RE: RPL stackrobatics decoder - Claudio L. - 07-10-2018, 04:42 PM
RE: RPL stackrobatics decoder - pier4r - 07-11-2018, 11:24 AM



User(s) browsing this thread: 1 Guest(s)