Guessing game

Mark Waddingham mark at
Tue Apr 3 06:06:13 EDT 2018

On 2018-04-03 11:35, David Bovill via use-livecode wrote:
> True - I’d rather be first-class than complete anyway.

To use a more concrete analogy - all British citizens are (since 
suffrage!) 'first-class' in the sense they can vote, but are not 
'complete' in the sense that there exist things which some citizens are 
allowed to do, which others are not.

> And yes thanks for suggested way around incompleteness. I still 
> suffered
> culture shock. The use-case I had was to replace send syntax with the 
> more
> elegant set the ... of object to syntax. I found myself wanting a bit 
> more
> power ...

That's a slightly different thing - I'd suggest that even your proposed 
'more elegant' solution is actually probably much less readable than 
using 'send' in the long run as, if I read that line it isn't entirely 
clear what it is intending to do...

So, I'm guessing what you really want to be able to do is:

   set the textColor of chunk tChunk of tMyObject to light-grey for each 
tChunk in spellingArray

Or (with slightly less use of non-existant syntax):

   set the textColor of each element of spellingArray to light-grey

Where 'spellingArray' is a numeric list of chunk references. Which would 
be the same as:

   repeat for each element tMisspeltWordsChunk in spellingArray
     set the textColor of tMisspeltWordChunk to "light gray"
   end repeat

Which does actually work now - as you can have things like "char 1 to 20 
of field 1" in a variable, which will be parsed at runtime when its the 
target of a set command.

> Power is not always a good thing. I’m glad that the dignity of arrays 
> has
> been restored.

Power and syntax are intimately related - in the sense that how we 
encode what we want to do as syntax will give us power in some ways, 
whilst removing it in others (the only way for that to not be the case 
is to make the syntax more verbose and more difficult to write - think 
machine code vs. LiveCode Script).

The above is actually a very good example of this as you *can* actually 
use an array as an index outside of setProps, it just means something 
perhaps much more useful...

   put "foo" into tPath[1]
   put "bar" into tPath[2]
   put tArray[tPath] into tBarOfFooOfArray

Numerically keyed arrays starting from 1 can be used as an array index, 
in which case they are considered to be a sequence of keys to follow. 
The above is the same as:

   put tArray["foo"]["bar"] into tBarOfFooOfArray

To put it another way, as it stands, the use of arrays as indexes in 
arrays has been chosen to mean something which is (to be fair) a *great 
deal* more useful than array-valued keys - as it makes array paths (i.e. 
sequence of keys) first-class in the language.

(Also, all uses of array-valued keys anywhere can be transformed to code 
which derives a canonical name from an array before being used as a key 
- which is probably something you should be doing anyway directly were 
you to ever think you have a need for such, otherwise it masks what the 
code is *actually* doing, as well as probably causing you horrendous 
performance problems for cases you have not foreseen and will occur!).

Of course, what you wanted (I presume) is a more succinct way to set a 
property of a collection of chunks to a single value - i.e. one which 
takes one line, rather than 3 - which isn't really anything to do with 
array-valued array keys at all - and more syntactic sugar for what other 
languages would call 'list comprehension' I guess.

Warmest Regards,


Mark Waddingham ~ mark at ~
LiveCode: Everyone can create apps

More information about the Use-livecode mailing list