repeating a string

Alex Tweedly alex at
Tue Mar 22 11:16:34 EST 2005

Frank D. Engel, Jr. wrote:

> Hash: SHA1
> If you use 'local' or 'global' to declare your variables, this is 
> true, unless you specify initial variables at this point.
> However, implicit variable declarations (just using the variable name) 
> causes them to be initialized to the name of the variable:

It's more subtle than that.

Implicit variable declarations used ONLY AS A SOURCE OF A VALUE do, as 
you say, *appear* to be initialized to the string of the name of the 
variable; but that's only a behaviour (or an appearance, if you like) - 
the variable is not actually initialized to that value, it remains 
implicit.   If the implicit variable is used as a source and target of 
the same operation, then it is initialized to empty.
Thus, the following code sequence
    put apples into t1
    put "abc" after apples
results in t1 containing "apples"
but apples containing only "abc"   - i.e. the first use did NOT 
initialize it.
If the variable apples was actually initialized as described, this would 
have resulted in apples containing "applesabc".

A scary example of that ......
I bet most Rev programmers would agree that
    put myVar+3 into myVar
   add 3 to myVar
mean the same thing (assuming myVar is an ordinary local variable).
But if myVar is an implicit, not yet initialized, variable, then the 
latter works ok, resulting in myVar containing 3; whereas
   put myVar + 3 into myVar
results in an execution error.

Another good reason for always declaring variables, and always quoting 
strings used as strings.

Alex Tweedly

No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.0 - Release Date: 21/03/2005

More information about the Use-livecode mailing list