List Commands Library for 50g

02032018, 08:55 PM
Post: #242




RE: List Commands Library for 50g
I've attached a beta release of the ListExt library with a few new commands to the first post in this thread. Gilles' LINSR command has been included. Here is its command description:
LINSR (List Insert) (alias: LINSRT) Input 3: { list of 0 or more objects } 2: any object or { list of objects } 1: number (insertion index) Output 1: { list with elements inserted at the indicated position } Inserts the object(s) given in stack level 2 into the list given in stack level 3, starting at the position indicated in stack level 1. An index value less than 2 will result in the new elements being added to the beginning of the source list, and a value greater than the length of the list will result in the elements being added to the end of the source list. Indices are rounded to the nearest integer in the range 0..1048575 prior to processing. Both the source list and/or insertion list (stack levels 2 and 3) may contain empty lists. Examples: { 1 2 3 5 6 } 4 4 LINSR => { 1 2 3 4 5 6 } { 1 2 3 } { 4 5 6 } 999 LINSR => { 1 2 3 4 5 6 } { 1 2 3 4 5 6 } { A B C } 5 LINSR => { 1 2 3 4 A B C 5 6 } { 1 2 3 } { A B C } 50 LINSR => { A B C 1 2 3 } { } { 1 2 3 } 50 LINSR => { 1 2 3 } On several occasions I have needed to create a list of numbers such as all odd/all even/every third/every fourth/etc. Noting the similarity of this type of operation to the methods used by LSEQ, I decided to add a command that creates an arithmetic sequence: LASEQ (List Arithmetic Sequence) Input 3: number (starting value) 2: number (common difference) 1: number (total number of elements in the result list) Output 1: { list containing the identified sequence } Provides a list of real numbers in sequence starting with the first number identified, then repeatedly adding the common difference to determine each successive value. The result list will always contain real numbers, regardless of the input given or numeric mode selected. Examples: 1 1 0 LASEQ => { } 1 2 5 LASEQ => { 1. 3. 5. 7. 9. } 0 0.25 11 LASEQ => { 0. .25 .5 .75 1. 1.25 1.5 1.75 2. 2.25 2.5 } 100 5 3 LASEQ => { 100. 95. 90. } 10 10 10 LASEQ => { 10. 20. 30. 40. 50. 60. 70. 80. 90. 100. } While creating the code for this command, I realized that it would be very easy to make a slight change to the main loop that would facilitate creating both geometric sequences as well as "division" sequences (what are those called?). So LASEQ/LMSEQ/LDSEQ all use the same engine for creating their sequences. The engine uses Saturn routines that are specific to real numbers, so the results are always in that domain (regardless of mode settings). That also makes them all reasonably good performers: LMSEQ (List Multiplicative Sequence) Input 3: number (starting value) 2: number (common ratio) 1: number (total number of elements in the result list) Output 1: { list containing the identified sequence } Provides a list of real numbers in sequence starting with the first number identified, then repeatedly multiplying the previous result by the common ratio to determine each successive value. The result list will always contain real numbers, regardless of the input given or numeric mode selected. Examples: 1 1 0 LMSEQ => { } 2 2 5 LMSEQ => { 2. 4. 8. 16. 32. } 1 1 10 LMSEQ => { 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. } 1 1.05 20 LMSEQ => { 1. 1.05 1.1025 1.157625 1.21550625 1.2762815625 1.34009564063 1.40710042266 1.47745544379 1.55132821598 1.62889462678 1.71033935812 1.79585632602 1.88564914232 1.97993159944 2.07892817941 2.18287458838 2.2920183178 2.40661923369 2.52695019538 } LDSEQ (List Division Sequence) Input 3: number (starting value) 2: number (common divisor) 1: number (total number of elements in the result list) Output 1: { list containing the identified sequence } Provides a list of real numbers in sequence starting with the first number identified, then repeatedly dividing the previous result by the common divisor to determine each successive value. The result list will always contain real numbers, regardless of the input given or numeric mode selected. Examples: 1 0 2 LDSEQ => Error: Infinite Result 1 3 5 LDSEQ => { 1. .333333333333 .111111111111 .037037037037 1.23456790123E2 } 59049 3 10 LDSEQ => { 59049. 19683. 6561. 2187. 729. 243. 81. 27. 9. 3. } Thanks again to Gilles for pointing out the lack of an insert command. Hopefully these new features will prove useful! 

« Next Oldest  Next Newest »

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