List Commands Library for 50g
|
06-27-2017, 02:52 PM
(This post was last modified: 06-27-2017 02:56 PM by DavidM.)
Post: #17
|
|||
|
|||
RE: List Commands Library for 50g
(06-26-2017 04:00 PM)DavidM Wrote: I've been thinking about the previously-mentioned "membership" test. Considering what it means for something to be a "member" of something else is a bit more complicated than I originally thought. For example... After putting more thought into this, I've come to the conclusion that trying to establish some form of "membership" concept would be too vague to be useful. We could attempt to come up with all sorts of specific cases where an object is part of some other object, but two things would happen as a result: - You'd have to look at the documentation every time you wanted to use the command just to see what might happen. - The code would have so many special cases that it would be a nightmare to maintain, and would probably be very slow as well. So that brings me full circle back to the concept of a modified form of LPOS, and that's what I'm now suggesting (and have a working copy of ). I've created a function I'm calling LPOSL (List Position/Sublists) which is essentially the same as LPOS with one difference: if the list element being compared to the target is a another list, it is considered a match if it contains the target value (regardless of where it is in that sublist). If the list element isn't a sublist, it is simply compared as normal for equality. To illustrate, here's a sample of how the two commands give different results: { { 1 2 3 } 2 1 } 1 LPOS => { 3 } { { 3 2 1 } 2 1 } 1 LPOSL => { 1 3 } LPOSL isn't recursive; it simply checks "one level down". This seems to be more in line with what you originally were seeking anyway, and hopefully is still general enough to be used in a variety of different scenarios. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)