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 }. 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:
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. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 37 Guest(s)