Post Reply 
RPL That Stack
11-23-2024, 05:07 PM (This post was last modified: 11-23-2024 08:28 PM by raprism.)
Post: #1
RPL That Stack
You may listening to Rattle That Lock and ...
  • learning RPL
  • want to showcase RPL code
  • ...

which is eventually 'Not quite HP', but tributable like e.g. for db48x.
Find all posts by this user
Quote this message in a reply
11-23-2024, 05:22 PM (This post was last modified: 11-29-2024 08:42 PM by raprism.)
Post: #2
RE: RPL That Stack - MVTO, CPTO, CD
These are db48x examples for some 'file-like management stuff' to move or copy objects to subdirs or paths (and related chdir command).

Code:

«
    @ Usage: 'obj1' { HOME sub1 subsub2 } MVTO
    Duplicate2 CPTO Swap
    Purge Drop
»
'MVTO' STO

«
    @ Usage: 'obj1' { HOME sub1 subsub2 } CPTO
    DirectoryPath
    → new old
    «
        Duplicate new CD Recall
        Swap Store old CD
    »
»
'CPTO' STO

«
    @ Usage: 'obj1' 'obj2' MV
    2 Pick Recall Swap Store
    Purge
»
'MV' STO

«
    @ Usage: { HOME sub1 subsub2 } CD
    @ Usage: { subdirhere } CD
        «
                →Prg Evaluate
        »
»
'CD' STO

Note that at first I was trying to make use of local variables all the times, but contrary to some HP48 examples it turned out on db48x that with my beginner level evaluation of variables 'kicked in' too often.
So time to train also some stack commands.

For sure some conditional tests could be added. But for now I was happy to get something working as intended.

I'm sure RPL experts will have some ideas for improvements. Looking forward to it.

EDITs:
  1. CD uses now MAP
  2. CD uses now →Prg
Find all posts by this user
Quote this message in a reply
11-29-2024, 07:51 PM
Post: #3
RE: RPL That Stack
(11-23-2024 05:22 PM)raprism Wrote:  These are db48x examples for some 'file-like management stuff' to move or copy objects to subdirs or paths (and related chdir command).

Code:

«
    @ Usage: 'obj1' { HOME sub1 subsub2 } MVTO
    Duplicate2 CPTO Swap
    Purge Drop
»
'MVTO' STO

«
    @ Usage: 'obj1' { HOME sub1 subsub2 } CPTO
    DirectoryPath
    → new old
    «
        Duplicate new CD Recall
        Swap Store old CD
    »
»
'CPTO' STO

«
    @ Usage: 'obj1' 'obj2' MV
    2 Pick Recall Swap Store
    Purge
»
'MV' STO

«
    @ Usage: { HOME sub1 subsub2 } CD
    @ Usage: { subdirhere } CD
        «
                Duplicate Evaluate
        »
        Map Drop
»
'CD' STO

Note that at first I was trying to make use of local variables all the times, but contrary to some HP48 examples it turned out on db48x that with my beginner level evaluation of variables 'kicked in' too often.

Local variables are evaluated on DB48x unlike RPL. This is notably because I like putting subprograms in a local variable and executing it like a regular program. This is one of the deviations from HP RPL that is both intentional and has no flag controlling it. I could certainly add such a compatibility flag. If you don't want evaluation, you can always quote the variables.

Quote:So time to train also some stack commands.

For sure some conditional tests could be added. But for now I was happy to get something working as intended.

I'm sure RPL experts will have some ideas for improvements. Looking forward to it.

EDITs:
  • CD uses now MAP

I think an alternative to your CD would be:

Code:

«
    @ Usage: { HOME sub1 subsub2 } CD
    @ Usage: { subdirhere } CD
    →Prg Evaluate
»

DB48X,HP,me
Find all posts by this user
Quote this message in a reply
11-29-2024, 08:39 PM
Post: #4
RE: RPL That Stack
(11-29-2024 07:51 PM)c3d Wrote:  
(11-23-2024 05:22 PM)raprism Wrote:  [...]
Note that at first I was trying to make use of local variables all the times, but contrary to some HP48 examples it turned out on db48x that with my beginner level evaluation of variables 'kicked in' too often.

Local variables are evaluated on DB48x unlike RPL. This is notably because I like putting subprograms in a local variable and executing it like a regular program. This is one of the deviations from HP RPL that is both intentional and has no flag controlling it. I could certainly add such a compatibility flag. If you don't want evaluation, you can always quote the variables.
[...]
No urgent need for compatibility flag - will try to make use of quotations.

(11-29-2024 07:51 PM)c3d Wrote:  [...]
I think an alternative to your CD would be:

Code:

«
    @ Usage: { HOME sub1 subsub2 } CD
    @ Usage: { subdirhere } CD
    →Prg Evaluate
»

Thanks for your hints. This alternative looks ideal.
Find all posts by this user
Quote this message in a reply
12-19-2024, 09:17 PM (This post was last modified: 12-19-2024 09:28 PM by raprism.)
Post: #5
RE: RPL That Stack
After reading about a PAD program in HP50g AUR to produce padded text I wondered how to get some kind of print command PrLn with right-aligned output. The following example just makes use of the normal text size, and spacing to get 8 lines of output:
Code:

Directory {
    PrLn
        «
            @ Usage: <obj> <lineno> PrLn
            → o l
            «
                o →STR
                { 10 } 6.70 l 1.50
                * - +
                { 2 FALSE FALSE -1
                    0 } +
            »
            DISP
        »
    TPrLn
        «
            1 8
            FOR i
                i 8 / →Q 1 TOLIST
                i * i PrLn
            NEXT
        »
}
'DPrLn' STO

The output of the test function TPrLn is:
   


Attached File(s)
.bmp  TPrLn.bmp (Size: 12.31 KB / Downloads: 4)
Find all posts by this user
Quote this message in a reply
Yesterday, 10:04 PM
Post: #6
RE: RPL That Stack
(12-19-2024 09:17 PM)raprism Wrote:  After reading about a PAD program in HP50g AUR to produce padded text I wondered how to get some kind of print command PrLn with right-aligned output.

Some bad news, some good news:

The bad news first: the default fonts on DB48x are variable-width, and there is no function to measure the width of a glyph or the width of some text. So making the computation of the width ahead of time is not possible with the current software.

The good news: The DISP / DrawText command has options to control horizontal and vertical alignment for text. There is even an example in the demo file:

Code:

    0 GRAY Foreground 1 GRAY Background
    " Align left "     { 10#000 10#120 2 true true  1  0 } Disp
    " Align Right "     { 10#400 10#120 2 true true -1  0 } Disp
    " Center "     { 10#200 10#120 2 true true  0  0 } Disp
    " Align Top "     { 10#200 10#000 2 true true  0  1 } Disp
    " Align Bottom " { 10#200 10#240 2 true true  0 -1 } Disp

Fractional input is allowed, so you can align "one quarter to the left".

DB48X,HP,me
Find all posts by this user
Quote this message in a reply
Post Reply 




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