48G: A little list-processing help? - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: 48G: A little list-processing help? (/thread-225730.html) |
48G: A little list-processing help? - Peter Murphy (Livermore) - 06-26-2012 On level 2 I have a list, say {2 3 5 7 11 13 17}. On level 1 I have a list of index numbers, {1 3 5 6}. As output I'd like a list of the first, third, fifth and sixth elements in the level-2 list, namely {2 5 11 13}. How do I do that, in general?
Thanks for a lesson.
Re: 48G: A little list-processing help? - Luiz C. Vieira (Brazil) - 06-26-2012 Hi. I cannot figure a solution for now, but I'd suggest reading about DOLIST and DOSUBS. Sorry not helping some more. Cheers.
Luiz (Brazil)
Re: 48G: A little list-processing help? - Raymond Del Tondo - 06-26-2012 I never needed the list processing functions, « -> a b
Not very elegant, but straightforward;-)
Re: 48G: A little list-processing help? - Gilles Carpentier - 06-26-2012 Hi, there is a lot of way to do this. For example :
or
Re: 48G: A little list-processing help? - Peter Murphy (Livermore) - 06-26-2012 Thanks to Luiz for encouragement, to Raymond for one lesson and to Gilles for two. All three solutions work as claimed, and all three will teach me something. Maybe even a lot.
What a wonderful resource this forum is!
Re: 48G: A little list-processing help? - Pascal Zeihen - 06-27-2012 Hi, Here is another solution, using DOLIST. Just put your lists in stack levels 2 and 1, as described, and execute this program:
<< SWAP -> L
Best regards.
Re: 48G: A little list-processing help? - Raymond Del Tondo - 06-27-2012 As written in my earlier post, the obvious loop version doesn't look Slightly OT, but just for the fun, here's a much faster SysRPL version.
:: CK2
This could be made even faster using meta objects, but the necessary offset calculations would also make the code somewhat more complicated, at least for this example;-)
Re: 48G: A little list-processing help? - Peter Murphy (Livermore) - 06-27-2012 Thank you, Pascal. Ma coupe déborde.
All the best,
Re: 48G: A little list-processing help? - Raymond Del Tondo - 06-27-2012 For those still interested, I made some timing measurements.
Timings are as follows:
DOSUBS1 is the slowest version, which also leaves the input list in level 2, DOSUBS2 is faster than the other UserRPL solutions since it only uses one implicit LAM binding.
The DOLIST version and the DOSUBS2 version are essentially the same,
The SysRPL version is much faster because much of the UserRPL overhead is not there.
Re: 48G: A little list-processing help? - Gilles Carpentier - 06-27-2012 Thank's for the benchmark ! I think that with a more complex example, the difference between "FOR" and "DOSUBS" or "DOLIST" will be greater. In general I noticed that the use of {} followed by numerous + is very slow. Best way is to use the stack and a ->LIST command at the end to collect all the datas. In my opinion, the 'ideal' implementation would be simply :
{2 3 5 7 11 13 17} -> { 2 5 11 13 }
But GET don't work that way, on the contrary of other commands. (probably becaus GET already accept a {} structure for the POS argument in some situations) But in general, it works, and without DOSUBS or DOLIST... For exemple, try :
{ 0 10 20 30 40 } SINetc. In some case, this is very powerfull See AUR pages F-1
Edited: 27 June 2012, 1:38 p.m.
Re: 48G: A little list-processing help? - Kiyoshi Akima - 06-27-2012 You could probably speed up the SysRPL a bit more by replacing the SWAP and LOOP with a SWAPLOOP. If nothing else, it'll trim 2.5 bytes off the program size.
|