|
symbols and upper/lower case
At 16:22 20.01.99 -0500, Brian Kaplan wrote:
>Variables with a hash (#) in front of them are symbols, and are
>case-insensitive. Therefore:
<snip>
>The REAL question here is why
>are some of the symbols in a property list uppercase and some are lowercase?
>My guess is that symbols are stored in a symbol table somewhere, and when
>any symbol is first used, it is added to the table using whatever
>capitalization it was first created in. When that symbol is used
>thereafter, it is simply looked up in the table. Probably some of the
>symbols being used here have already been used somewhere else (and added to
>the symbol table), and so the case was already set when the symbol was first
>used. Anyone know the real answer?
>
I think it is just like you describe it. this common lookup table persists during a
director session. When another dir-file is opened director scans the file for handler
names, variables etc and adds those to the clt. This can have irritating effects since
even deleted parts of scripttext may find their way into the look up table.
You can get the position of a symbol in the symbol look up table by something like
put #a
-- #a
put #B
-- #B
put #a + 1
-- 1222
put #b+1
-- 1223
You can use this to test whether a symbol was already defined, however, it will be defined
after you tested it once.
init (script "testclt")
put getIndexOfSymbol((script "testclt"),#a
-- 1221
put getWasAlreadyDefined ((script "testclt"),#a)
-- 1
put getWasAlreadyDefined ((script "testclt"),#howdy)
-- 0
-------------------------------------------
-- parent script testCLT
property myLastCLT
on init me
set myLastCLT = symbol("foo" & string(the ticks) & "bar")
return myLastCLT
end
on getIndexOfSymbol me,dSymbol
if not symbolP(dSymbol) then return
return (dSymbol + 1) - 1
end
on getWasAlreadyDefined me,dSymbol
if not symbolP(dSymbol) then return
set lastIndex = getIndexOfSymbol(me,myLastCLT)
set thatIndex = getIndexOfSymbol(me,dSymbol)
return (thatIndex < lastIndex)
end
------------------------------------------------------
The above is d6, I didn't test d7 for differences yet.
|