(49G) (49g+) (50g) (48gII) NMDUP
|
05-16-2018, 06:12 PM
(This post was last modified: 11-11-2018 12:58 PM by DavidM.)
Post: #1
|
|||
|
|||
(49G) (49g+) (50g) (48gII) NMDUP
DUPN and NDUPN are very useful RPL commands that also happen to be very fast ways of replicating objects on the stack. DUPN makes a single copy of the number of objects specified:
1 2 3 3 DUPN => 1 2 3 1 2 3 ...and NDUPN makes a single object with the specified number of copies, followed by the number of copies: 7 8 9 3 NDUPN => 7 8 9 9 9 3. Another similar scenario that can be useful has no single command, though. Specifically, replicating a group of objects a set number of times. The following SysRPL program can be used to perform this function: Code: :: Compile the above and give it a suitable name (I use NMDUP). To use it, place two numbers on the stack which represent the following: 2: N (the number of elements in the stack to replicate/group size) 1: M (the number copies of the elements to make) Note that M represents the total quantity of duplicates, not the additional ones. So a quantity of 0 is the same as dropping N elements, a quantity of 1 does nothing, etc. Likewise, an N of 0 will have no affect on the rest of the stack, as there are no stack items identified for replication. Examples: 1 2 3 3 0 NMDUP => <nothing> 1 2 3 3 1 NMDUP => 1 2 3 1 2 3 3 2 NMDUP => 1 2 3 1 2 3 1 2 3 2 5 NMDUP => 1 2 3 2 3 2 3 2 3 2 3 1 2 3 0 5 NMDUP => 1 2 3 |
|||
08-11-2018, 04:11 PM
Post: #2
|
|||
|
|||
RE: (49G 49g+ 50g 48gII) NMDUP
Just noticed a typo, it should be DUPN, NOT NDUP for the built-in command.
|
|||
08-11-2018, 04:22 PM
Post: #3
|
|||
|
|||
RE: (49G 49g+ 50g 48gII) NMDUP
(08-11-2018 04:11 PM)John Keith Wrote: Just noticed a typo, it should be DUPN, NOT NDUP for the built-in command. Thanks for spotting that -- it's now fixed. Note that NDUP is the SysRPL version, DUPN is the UserRPL one. That same pattern holds for several other commands as well. Sometimes my fingers don't switch modes as quickly as my brain tries to. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)