"do" statements and value function

J. Landman Gay jacque at hyperactivesw.com
Sun Jun 19 23:48:24 EDT 2011


On 6/19/11 4:10 PM, Timothy Miller wrote:

> Is it true that the "do" command and the "value" function perform
> about the same tasks in different ways? I.e., is it true that you can
> avoid "do" by judicious use of "value"?

They are for different purposes and not really interchangeable. The 
value function is more limited than "do", it just returns a single 
evaluation of an expression. "Do" can execute a whole script at a time, 
but it has a lot of overhead and should be avoided when possible.

I have never needed to nest value() functions, as per your other post; 
there is almost always a better way. The example of value(value(line x 
of fld y)) is redundant; just "get line x of fld y" is enough to give 
you the text of the line. Most things you want to do are like that, 
there are usually alternatives.

You need value() occasionally to force an evaluation when there is no 
other way. For example, it is used to call a function remotely when the 
function isn't in the message path:

   put value("myFunction()",stack "mySubstack")

In many cases you don't need value() at all, just supplying parentheses 
will force an evaluation. Parentheses are required for that reason when 
getting the contents of a URL container:

   get url ("file:"& fileVarPath)

Without the parentheses the call will fail. The text must be evaluated 
into a functional URL before it can work, and the parentheses force that 
to happen.

A common purpose for "do", besides constructing variables or syntax on 
the fly, is to execute commands in another language:

   do field 1 as applescript

That will force the AppleScript compiler to load. If you are "do"ing 
something in LiveCode instead of applescript, then LiveCode's own 
compiler needs to load. A "do" is functionally similar to opening the 
script editor, typing some commands, and hitting the "compile" button.

There are so many built-in ways to get values that explicitly calling 
"do" (or value) isn't necessary very often, though sometimes there is no 
way around it. If you want to post a few of your own "do" examples, 
maybe we can see if there is a different way to execute them.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list