Re: A question on technique
Re: A question on technique
- Subject: Re: A question on technique
- From: Axel Luttgens <email@hidden>
- Date: Mon, 16 Mar 2015 16:36:56 +0100
Le 15 mars 2015 à 22:33, Gil Dawson a écrit :
> Hi--
>
> I wish to translate a sequence of codes into corresponding mnemonics.
>
> Two same-length properties encode the correspondence.
>
> property Codes : {"9420", "94ae", "94d0", "942f", "942C", "9470"}
> property Mnemonics : {"RCL", "ENM", "ReW", "EOC", "EDM", "RfW"}
>
> Eventually I expect the two lists to be much larger.
>
> The following code works well enough...
>
> on MnemonicOf(aCode)
> [...]
>
> ...but is there another, perhaps faster, way to do this?
Hello Gil,
As far as speed is concerned, there are some (mysterious) "old tricks".
For example, this simplified version of your handler:
on MnemonicOf(aCode)
local k
repeat with k from 1 to length of Codes
if item k of Codes is aCode then return item k of Mnemonics
end repeat
return missing value
end MnemonicOf1
may be rewritten as:
on MnemonicOf(aCode)
local k
repeat with k from 1 to length of my Codes
if item k of my Codes is aCode then return item k of my Mnemonics
end repeat
return missing value
end MnemonicOf
so as to cheaply achieve an impressive speed improvement.
> I think of constructs like...
>
> if aCode is in Codes then...
>
> ...but I don't see how to index the Mnemonics list.
>
> I think of maybe using records, but I don't see quite how.
Indeed, AppleScript's record keys are defined at compile time, and this inhibits dynamic accesses thru arbitrary keys; there is thus no equivalent of associative arrays or such in AppleScript.
Best regards,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden