local and do <commands> - what NOT to do

Mark Waddingham mark at livecode.com
Thu Feb 18 07:01:59 EST 2016

On 2016-02-18 12:46, [-hh] wrote:
> Just now I can't think of an example for *generating* variable names 
> only.
> But there are very simple and important ones for *using* variable 
> names:
> local a1=1, a2=false
> -- local a[1]=1, a[2]=false #<-- currently not allowed
> For such default-constructs variable names and using "do" are really 
> helpful.

Although you can do the above as:

   local a -- only needed if in strict compilation mode
   put 1 into a[1]
   put false into a[2]

Whilst this is 2 or three lines as opposed to 1, I'd argue that that 
small amount of extra verbosity makes things easier to read.


   local a -- only needed if in strict compilation mode
   put 1,false into a
   split a by comma

Which can be generalized to an arbitrary number of elements in a, for 
only 2/3 lines.

Also, both of the above patterns are substantially more efficient than 
using 'do' which is horrendously inefficient - after all it has to 
compile the snippet of code you want to do and then execute it... As 
opposed to just executing what has previously been compiled if you don't 
use 'do'.

Warmest Regards,


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

More information about the use-livecode mailing list