Guessing game

Mark Waddingham mark at livecode.com
Tue Apr 3 05:24:22 EDT 2018


On 2018-04-03 10:28, David Bovill via use-livecode wrote:
> Arrays as first class citizens? Give them a passport! Arrays have 
> rights
> too!
> 
> Need to check if they can be passed as parameters in setprop handlers - 
> as
> in “set the beautiful_Colour [spellingArray] of my card to light-grey”

Heh - okay let me define what I mean by 'first-class citizen'...

A 'thing' in a programming language is a 'first-class citizen' if it can 
be placed in a variable, and further being then able to use that 
variable to be able to access the functionality of 'thing' instead of 
referencing 'thing' directly. i.e. 'thing' can be indirected.

The above example confuses two things - the idea of being first-class, 
and the ability to use a given type of value in a given context. SetProp 
handlers are defined to take a string argument, as they are backed by a 
LiveCode array (custom property set) if there is no handler to call (or 
if messages are locked). So that's just a case of functionality which 
has not been defined nor implemented.

Perhaps the best example of a language feature which is nearly never 
'first-class' (as in, I don't believe there are any widely used general 
programming languages which allow it) is types. e.g. You can't do things 
like the following:

   put integer between 1 and 3 into tIntBetween1And3Type
   put tMyString as tIntBetween1And3Type into tIntBetween1And3

Certainly you can approximate this in various languages - you *can* 
build concrete instances of abstract base classes (i.e. ones with all 
virtual methods) in C++ at runtime if you don't mind a bit of 
bit-bashing; but you can't build a struct, or class which is used as a 
value (i.e. not passed around as a pointer) which existing compiled code 
can used.

Warmest Regards,

Mark.

P.S. Looking at this another way - I'd perhaps characterize the above as 
arrays are not 'complete' as values in LiveCode (as in: you can't use 
arrays in all places where you can use strings, and would still make 
sense), but I would say they were 'first-class'. I'd suggest 
'completeness as values' is a more stringent requirement than 
'first-class' - and is more that 'code has not been written to do that' 
(incomplete), rather than the 'model of the language disallows any 
notion of it being possible' (not first-class).

P.P.S. You could rewrite your example as:
     set the beautiful_Colour [ the arrayEncode of spellingArray ] of 
this card to "light-grey"
Which suggests that arrays are actually 'complete' in LiveCode in the 
sense suggested above - it is just you (as the coder) have to work a bit 
harder to use them as such.

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




More information about the Use-livecode mailing list