Post Reply 
HP 50g List function question
09-10-2017, 03:28 PM
Post: #9
RE: HP 50g List function question
My attempt at this ended up being the same as Jeremy Hawdon's from John Keith's post. But the GoferList version is going to be hard to beat Smile.

As for the secondary question (deleting n elements from end/splitting a list):

I wouldn't use LRMOV for this, as it is designed with a different purpose in mind (deleting arbitrary, possibly non-contiguous elements as identified in a list argument).

If you were to use the ListExt functions, there's several ways to approach it. Which one to use probably depends on the source of "n" and/or the intended use of the result.

Probably the easiest is to use one of the newer commands (LFRST). If n is defined as the number of leading elements to keep:
Code:
{ 1 2 3 4 5 6 } 4 LFRST => { 1 2 3 4 }

Another of the newer commands (LRSPL) can be used if you know the complementary number (n becomes the number of trailing elements to delete). It splits the given list into two by setting the split point counting from the right:
Code:
{ 1 2 3 4 5 6 } 2 LRSPL => { { 1 2 3 4 } { 5 6 } }

...then you would simply need to GET the first sublist. So combining the two operations together becomes:
Code:
{ 1 2 3 4 5 6 } 2 LRSPL 1 GET => { 1 2 3 4 }

If what you really wanted was simply "n" trailing elements, use the following:
Code:
{ 1 2 3 4 5 6 } 2 LLAST => { 5 6 }
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP 50g List function question - Andres1 - 09-09-2017, 10:47 PM
RE: HP 50g List function question - pier4r - 09-10-2017, 07:18 AM
RE: HP 50g List function question - pier4r - 09-10-2017, 09:40 AM
RE: HP 50g List function question - pier4r - 09-10-2017, 07:46 AM
RE: HP 50g List function question - DavidM - 09-10-2017 03:28 PM
RE: HP 50g List function question - Juan14 - 09-10-2017, 07:41 PM



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