Programming puzzles: processing lists!
|
06-12-2017, 08:37 AM
(This post was last modified: 06-12-2017 10:05 AM by pier4r.)
Post: #137
|
|||
|
|||
RE: Programming puzzles: processing lists!
So while I'm attacking the #33 I see a similar problem to the #20 (that it is still not solved in RPL, by me at least).
With the #20 I am stuck on debug problems in case of nested iterations on a list, like: Code:
If I try to do this with nested DOSUBS/DOLIST either I am super careful, or debugging it is very taxing. So aside creating my own debug friendly dosubs/dolist (I am not so motivated) what could be workarounds since I need to iterate over a list? Iterating with a FOR index L1 index GET NEXT is super slow for the quick test I made. (maybe in other 50g languages is faster) The library of David gave me an idea (maybe an idea also for him?). Another way to iterate over a list is to rotate the list and get the head. Or consume the list (from the head/tail). Another alternative still is to explode the list before the iteration, and then working on it with stack operations. But that is very messy in stack terms. One has to debug carefully. Therefore I try to ask some more functions for the David Library, of course it is a wish no pressure whatsoever. Having list operations (that I partially coded in userRPL) to iterate over a list in several ways: - L1 listHead: returns on stack 2 the list, without the head, on stack 1 the head of the list { 1 2 3} -> { 2 3 } 1 - L1 listTail: returns on stack 2 the list, without the tail, on stack 1 the tail of the list {1 2 3 } -> {1 2} 3 - L1 <num> listHeadIterate: returns the first <num> elements from the head of the list (in case it repeats making circle of the list), plus the list rotated (so the num+1 element now is in the head). { 1 2 3 4 5 } 2 -> { 3 4 5 1 2 } 1 2 - L1 <num> listTailIterate: returns the first <num> elements from the tail of the list, and then the list rotated { 1 2 3 4 5 } 2 -> { 4 5 1 2 3 } 5 4 - those above could be extended on multiple lists. To partially substitute DOLIST . - other possible functions to iterate over/consume a list (a collection of lists)? (will be interesting to compare those with FOR + get , of course dolist/dosubs will be always faster) I believe if I go through processing challenges using David's library, I'll find a couple more requests for sure. Again, I don't want to make pressure, those are just wishes. (I also believe that through -reasonable- wishes a library can grow very useful) Main source repository changed the url: https://app.assembla.com/spaces/various-...Operations Also #22 Code:
also #33 Code:
Wikis are great, Contribute :) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 11 Guest(s)