Programming puzzles: processing lists!

05252017, 04:33 PM
Post: #91




RE: Programming puzzles: processing lists!
OK. I stewed on this for a bit (over)thinking through various options, but ultimately decided to leave things as they were.
For a short time, I considered having the commands check the status of system flag 105 (exact/approximate mode) to see whether they should use the faster equality check (1<>1.) or the slower one (1=1.). But ultimately I feel it's more important that the commands produce consistent results. So I opted against that. Besides the resounding feedback , the kicker for me was the realization that the internal command that LDDUP uses (COMPRIMext) also treats integers and reals as not being equivalent. Keeping the other commands asis maintains consistency with how this builtin command operates. As has already been mentioned, it's simple enough to use I→R on a list to convert all the integers to reals before further processing. That mitigates any potential equivalency issues, and therefore allows all of the routines that need to perform these checks to use the faster methods. All of these commands were implemented in a Debug4x project as standard SysRPL objects, with a small amount of Saturn code sprinkled in as well. I'll be happy to share it with anyone that's interested  PM me if you'd like to receive it. I do consider this to be a work in progress, so updates may occur at any time. Here's a complete list of the commands included in the attached library (#1423): LCNT (List Count) Input 2: { list of 0 or more objects } 1: Any object Output 1: Count Returns the number of instances of the object in SL1 that exist in the list from SL2. LDDUP (List DeDup) Input 1: { list of 0 or more objects } Output 1: { same list with duplicates removed } The objects in the result list are in the same order encountered in the original list. LEQ (List Equal) Input 1: { list of 0 or more objects } Output 1: 0 (FALSE) or 1 (TRUE) Checks to see if there are any nonmatching elements in the list. For purposes of this function, an empty list assumes a result of TRUE as there are no nonmatching elements. Likewise, a list of 1 element is also assumed to be TRUE for the same reason. LGRP (List Group) Input 1: { list of 0 or more objects } Output 1: { list of 0 or more objects } Returns the same list with only the first instance of any objects that are repeated. Objects are in the same order as they are encountered. LMRPT (List Multiple Repeat) Input 2: { list of 0 or more objects } 1: repeat factor [integer] Output 1: { list with same objects from SL2 input repeated as directed by repeat factor } A repeat factor of 1 returns the same list. A repeat factor of 0 returns an empty list. Otherwise, the list contents are repeated in the same order as in the original list. LREPL (List Replace) Input 3: { list of 0 or more objects } 2: { list of target objects } 1: { list of replacement objects } Output 1: { list from SL3 with objects matched in SL2 list replaced by objects in SL1 list } Example { 1 2 3 } { 1 3 } { 7 8 } LREPL result: { 7 2 8 } LROT (List Rotate) Input 2: { list of 0 or more objects } 1: rotation value [integer] (neg. for left rotation, pos. for right) Output 1: { list of 0 or more objects } Returns the same list rotated per the given rotation value. A value of 0 leaves the list unchanged. Rotation wraps accordingly if the rotation value is greater than the size of the list. LRPCT (List Repeat Count) Input 1: { list of 0 or more objects } Output 1: { { L1 } { L2 } } L1: Same as LGRP result L2: The count of each item in L1 that was in the input list An empty list will result in a list of two empty lists { } => { { } { } } for consistency. Example { 1 1 1 2 3 1 } LRPCT result: { { 1 2 3 1 } { 3 1 1 1 } } LSHF (List Shuffle) Input 1: { list of 0 or more objects } Output 1: { same objects as input, in random order } Randomizes the order of the elements in the list given as input. LSUM (List Sum) Input 1: { list of 0 or more objects } Output 1: <the result of the list elements added together> This command is essentially the same as ΣLIST, but it also accepts an empty list or a list with only 1 element as input. An empty list as input results in 0. The sum of a single element is simply that same element. Object types must be compatible for addition or an error will result. LSWP (List Swap) Input 3: { list of 0 or more objects } 2: index1 [real] 1: index2 [real] Output 1: { list of 0 or more objects } The result is the same list with elements <index1> and <index2> swapped. 

« Next Oldest  Next Newest »

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