HP Forums
RPL That Stack - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: Not HP Calculators (/forum-7.html)
+--- Forum: Not quite HP Calculators - but related (/forum-8.html)
+--- Thread: RPL That Stack (/thread-22755.html)



RPL That Stack - raprism - 11-23-2024 05:07 PM

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.


RE: RPL That Stack - MVTO, CPTO, CD - raprism - 11-23-2024 05:22 PM

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



RE: RPL That Stack - c3d - 11-29-2024 07:51 PM

(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
»



RE: RPL That Stack - raprism - 11-29-2024 08:39 PM

(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.