This is a very subtle one. The problem is that "datum" is never
created as a variable in your script. The solution is to force it to
be created, either with something like "put empty into datum" or by
declaring it "local datum" at the top of the handler.
For afficiandos of language design, the details: both MetaCard and
HyperCard are lexically scoped (a token becomes a variable the first
place something is stored into it). For example:
put x into somevar # somevar now has the literal "x" in it
put 10 into x
put x after somevar # somevar now has the number 10 in it
Unlike HyperCard, MetaCard statically binds variable references
because it preprocesses ("compiles") an object's script the first time
a message is sent to that object. HyperCard, on the other hand,
retokenizes the script as it is being executed, which is similar to
the way dynamically scoped languages like the UNIX shells work. The
HyperCard way is not only much slower (this is the primary reason the
MetaCard interpreter runs about twice as fast as HyperCard's on
equivalent hardware), but can also can also result in hard to predict
behavior:
on someMessage x, y
if x > y then put 10 into somevar
put somevar
end someMessage
In MetaCard, the put command puts either 10 or empty into the Message
Box because somevar is a variable at that point in the script. In
HyperCard, it will put 10 sometimes and "somevar" sometimes depending
on whether x > y. But which of these behaviors is better is really a
moot point, IMHO, because the real problem here is sloppy scripting,
not defects in the interpreters.
put the seconds + 20 into somevar
repeat while x > somevar
put the seconds into x
end repeat
In MetaCard, this will be an infinite loop since the literal "x" in
the condition of the repeat loop will always be greater than the
number in the variable somevar. In HyperCard, the first time the
condition is evaluated, x is treated as a literal "x", and the loop is
executed. The second time through the loop, x is a varible with a
number in it and the loop will stop executing.
The same kind of strange behavior can result with "do". In MetaCard
script above, nothing is stored into the variable datum at parse time
so it is treated as a literal throughout the script. When the "do"
statement is executed, datum is created as a variable local to the
"do" context, which isn't passed back out to the main script context.
So, the take home message is: when in doubt, always declare variables
or initialize them explicitly. If you take the lazy way out and
depend on the language feature of automatic variable creation, you run
the risk of creating a script with very hard to find bugs in it.
Scott
> Annegret
>
> Annegret Duda | Tel.: 49 6151 16-3510
> Rechnerbetriebsgruppe FB 20 |
> TH-Darmstadt | e-mail: duda@rbg.informatik.th-darmstadt.de
> Merckstrasse 25 |
> |
> 64283 Darmstadt |
> Germany |
>
-- *********************************************************************** * Scott Raney 303-447-3936 Remember: the better you look, * * raney@metacard.com the more you'll see -- Lidia * ***********************************************************************