Post Reply 
DB48X: HP48-like RPL implementation for DM42
09-04-2024, 07:11 PM
Post: #288
RE: DB48X: HP48-like RPL implementation for DM42
(09-04-2024 04:58 PM)c3d Wrote:  1/ MAP / REDUCE / FILTER. I used the now traditional terminology for these operations. The HP48 calls REDUCE "STREAM", and that alias is accepted. I don't think that RPL has a direct equivalent to FILTER, which is used to build a list from items for which a predicate is true. For example, to filter only odd values in a list, you can use { 1 2 3 5 6 7 8 11 9 } << 2 MOD >> FILTER, and you get { 1 3 5 7 11 9 }.

2/ FOR loop with a list input. For example 0 { A B C D E } FOR I I 2 * 1 + + NEXT returns 2*A+2*B+2*C+2*D+2*E+5 (assuming none of the variables is defined).

Part of the problem I have with DOSUBS and DOLIST is the special treatment they make of commands based on the number of arguments that they take. I have the infrastructure in DB48X to replicate that functionality, but it will take a lot of testing with the HP48 and HP50 to see how that behaves on real HP machines. People who use DOSUBS tend to know what they are doing ;-)

DOLIST is relatively straightforward. With a single list argument it is just map. With two or more lists it is essentially zipWith, the difference to other languages being that the arguments (one from each list) appear on the stack, rather than as a sublist or tuple.

DOSUBS is rather strange, I don't know of an equivalent in any other language. It sure is useful though, and RPL would be poorer without it. DOSUBS ,with a numerical argument n, gives its function argument an n-element subsequence of the list but again the elements appear on the stack. For instance,
Code:

{ 1 2 3 4 5 6 7 8 9 10 } 3
<< + +
>> DOSUBS
returns { 6 9 12 15 18 21 24 27 }.

There is no exact equivalent to filter in RPL but it can be faked with DOLIST or DOSUBS. ListExt and LstX do have filter as well as many other list processing functions, most of which come from Haskell, particularly from the package Data.List. While many of these functions can also be reproduced with built-in RPL commands, the ListExt functions are much faster, sometimes by orders of magnitude.

Please forgive me if the above is already obvious to you, but i want to make sure that these rather unusual commands are well understood.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
DB48X v0.4.8 is out - c3d - 10-22-2023, 11:31 PM
Release v0.5.0: Statistics and flags - c3d - 11-20-2023, 08:57 AM
v0.6.5: Minor bug fixes - c3d - 02-11-2024, 11:23 PM
Release 0.7.1 "Whip" - Bug fixes - c3d - 03-04-2024, 12:46 AM
DB48X v0.7.4 release is out - c3d - 04-14-2024, 03:05 PM
DB48X v0.7.6: Solving menu - c3d - 05-13-2024, 12:04 AM
DB48X v0.7.7: Units in solver - c3d - 06-02-2024, 11:36 PM
v0.7.10 - Interactive stack - c3d - 07-14-2024, 11:31 PM
DB48X v0.7.13 is out - c3d - 08-05-2024, 07:31 AM
DB48X v0.7.15 - c3d - 08-25-2024, 08:45 PM
DB48X v0.7.16 - c3d - 09-02-2024, 01:36 AM
DOSUBS command - grbrum - 09-04-2024, 03:37 PM
RE: DB48X: HP48-like RPL implementation for DM42 - John Keith - 09-04-2024 07:11 PM
v0.7.18 - APPLY, SUBST, WHERE - c3d - 09-15-2024, 11:58 PM
Program Editing Question - spiff72 - Yesterday, 03:27 PM



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