valueDiff for arrays?

Mark Waddingham mark at livecode.com
Sun Aug 5 15:33:56 EDT 2018


On 2018-08-05 21:22, Richard Gaskin via use-livecode wrote:
> Mark Waddingham wrote:
> 
>> 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?
> 
> In my own head, any name-value pair, even one in which the value is an
> empty string, is worth taking into account.

In the general case it depends on what data you are modelling with an 
array.

If an array key-value is modelling a field which is not optional, then 
there is no need to distinguish between an array key being there, and 
one not being there - i.e. all field accesses can be tRecord[tKey], and 
your key value can be empty.

If a field's value has to be non-empty to be valid, then you can test 
for existence of a field by doing tRecord[tKey] is not empty. So, again, 
presence or not presence of an array key is immaterial.

The only case where you need to treat no key-value as different from 
empty key-value is where a valid value for an optional field can be the 
empty string. In which case that field access needs to be structured as:

   if tKey is among the keys of tRecord then
     -- yay the key is there
   else
     -- oh, there is no key
   end if

This is because LC doesn't see the difference between the empty string 
and absence of a value - but you can model that with an array key-value 
which is optional.

Warmest Regards,

Mark.

-- 
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps




More information about the use-livecode mailing list