Arrays: new and old keys, i and, man am I annoyed

David Bovill david at vaudevillecourt.tv
Mon Sep 15 05:57:29 EDT 2008


2008/9/15 John Vokey <vokey at uleth.ca>

>
> on test
>  put 5 into array[fred]
>  put array[fred]
>  wait 2secs --wait for it
>  put 2 into fred
>  put array[fred]
> end test
>
> I have asked for ages (back when Metacard was but a pup) that array
> literals require quotes (the same discontinuity exists for properties---try
> it, please), and nothing.  But really, array["fred"] and array[fred] are
> really two different entities, no?  Even Rev treats them so, as long as
> fred, the variable (or fred the property) has been declared to have value.
>  This inconsistency is more than a little annoying; it is just stupid.


Ah - got you.  Now without testing - I would assume that Rev is doing what
it usually does with strings and variables - and not enforce quoting or
declaring.

So:

put fred into test -- puts the string "fred" into the variable test
answer test
put 2 into fred -- puts 2 into the undeclared variable fred.
answer fred

So I'd guess the script above would do the same - should put 5 and then
empty (creating an array with key "fred" then later initialising a variable
fred). Lets see... testing the script thats what happens. So from my point
of view this is the standard way Rev deals with variables - and this is the
same AFAIK as the way HyperCard did it - put fred is the same as put "fred".
It can be confusing to a programmer - but tolerates the lazy beginner. I'm
neutral on that one.

on mouseUp
>     test
>     exit to top
>
>     put fred into test -- puts the string "fred" into the variable test, as
> variable fred does nt exist yet.
>     answer test
>
>     -- but if fred was already initiated
>     put 2 into fred -- autmatically initalises variable fred
>
>     -- so now lets do line 1 again
>     put fred into test -- puts 2 into variable test (not the string
> "fred").
>     answer test
> end mouseUp
>
> on test
>     -- array example of same behaviour
>     put 5 into array[fred]
>     answer array[fred]
>
>     put 2 into fred
>     put "Hello new variable fred" into array[fred]
>     answer array[2]
>     answer array[fred] -- same thing
>
>     -- but we still have the orriginal key created in step 1
>     answer array["fred"]
> end test
>



More information about the use-livecode mailing list