valueDiff for arrays?
Monte Goulding
monte at appisle.net
Sat Aug 4 21:59:03 EDT 2018
Just to throw it out there I still want to add `each` to filter one day. So in this case I think it would be:
filter keys of tArray1 with expression \
each is among the keys of tArray2 and \
tArray1[each] is not tArray2[each]
> On 5 Aug 2018, at 11:23 am, Brian Milby via use-livecode <use-livecode at lists.runrev.com> wrote:
>
> Here is code that only uses LCS to accomplish the goal (only returning the
> keys where they exist in both arrays but the values are different). This
> is made to be similar to the way the existing functions work (with the
> option to mutate).
>
> command valueDiff @pDestinationA, @pLeftA, pRightA
> local tMutate, tLeft, tRight, tNewRight
> if the paramCount is 3 then
> put false into tMutate
> put pLeftA into tLeft
> put pRightA into tRight
> else
> put true into tMutate
> put pDestinationA into tLeft
> put pLeftA into tRight
> end if
> repeat for each key tKey in tLeft
> if tKey is among the keys of tRight and \
> tLeft[tKey] is not tRight[tKey] then
> put tRight[tKey] into tNewRight[tKey]
> next repeat
> end if
> delete variable tLeft[tKey]
> end repeat
> if tMutate then
> put tLeft into pDestinationA
> put tNewRight into pLeftA
> else
> put tLeft into pDestinationA["1"]
> put tNewRight into pDestinationA["2"]
> end if
> end valueDiff
>
> My question from an engine perspective is whether it would be faster to
> just generate both arrays instead of removing keys from tLeft. I decided
> to build the tNewRight to avoid iterating the keys of tRight.
>
> I'd be pretty confident that Mark's solution will be faster, even with 3
> iterations over the keys.
>
> On Sat, Aug 4, 2018 at 6:52 PM, Mark Waddingham via use-livecode <
> use-livecode at lists.runrev.com> wrote:
>
>> On 2018-08-04 21:00, Richard Gaskin via use-livecode wrote:
>>
>>> Mark Waddingham wrote:
>>>
>>> Yes - so come up with LCS handlers which do that, share them, let's
>>>> work together to make them as efficient in LCS as possible and then
>>>> see what we can do in the engine to improve their performance (which
>>>> I'm guessing is as much the purpose for the proposition as the
>>>> syntax).
>>>>
>>>
>>> It is, primarily. The minor convenience is nice too, but you know how
>>> much I love to see performance enhancements in the engine.
>>>
>>> As for implementation, Mark Wieder's looks good:
>>> http://lists.runrev.com/pipermail/use-livecode/2018-August/248862.html
>>>
>>
>> One important point here (which I think is something which is often
>> overlooked in LC as it is just something we deal with implicitly case by
>> case)...
>>
>> In your use-case for 'valueDiff' - do you need to tell the difference
>> between a key value being the empty string and a key value not being
>> present at all?
>>
>> [ i.e. using an array key absence to emulate 'nothing': meaning you are
>> actually storing nothing or a value (even the empty string). ]
>>
>> It might seem like a minor detail, but does change the operation somewhat
>> (and potential implementations).
>>
>> Warmest Regards,
>>
>> Mark.
>>
>> --
>> Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
>> LiveCode: Everyone can create apps
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list