Re: Accessing a Record by variable--"the" solutions
Re: Accessing a Record by variable--"the" solutions
- Subject: Re: Accessing a Record by variable--"the" solutions
- From: Richard 23 <email@hidden>
- Date: Thu, 15 Feb 2001 08:28:38 -0800
>
My thanks to Bill Cheesman, Ken Dobson, Arthur Knapp and Ric Phillips
>
for your solutions and in particular to Ric for the additional
>
illumination in his comment on, "de-referencing a label/variable via
>
the contents of another label/variable".
>
Now I have three solutions. (I don't believe I've missed any).
Only the one which actually does what I thought what asked for in the
first place which was to look up a value for a record using its label.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Olof <email@hidden> posted this 13 Feb 2001 (digest #364):
to getKeyFromRecord(aKeyString, aRecord)
try
(aRecord as text)
on error message
set recordText to text 12 thru -15 of message
end try
set keyPhrase to (aKeyString & " of " & recordText)
try
set sr to run script keyPhrase
on error
error ("Can't get " & keyPhrase)
end try
return sr
end getKeyFromRecord
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * *
I have posted similar handlers before, like this one:
on GetProp(theRec, theProp)
tell (run script "me
on f(theRec)
return theRec's " & theProp & "
end f") to f(theRec)
end GetProp
set theMonthRecord to {jan:1, feb:2, mar:3, apr:4, may:5}
GetProp(theMonthRecord, "mar")
--> 3
set theMonthRecord to {January:1, February:2, March:3, April:4, May:5}
GetProp(theMonthRecord, April)
--> 4
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * *
I hate it when interesting solutions go by without comment like Olof's
did.
But it shouldn't bother me. This too shall pass!
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * *
2 And is there a procedure which would ensure all three are
tested to the same base line?
I have a home brew benchmarcking script written in FaceSpan which accepts
script objects as parameters to a handler and it runs timed iteration
tests. I haven't released it yet. I'm still working on the code which
recognizes my own handlers so that they always appear to win!
R23