• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: A question on technique
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question on technique


  • Subject: Re: A question on technique
  • From: Barry Wainwright <email@hidden>
  • Date: Sun, 15 Mar 2015 22:30:11 +0000

You can avoid iterating the list by looking up a position:

property Codes : "x9420x94aex94d0x942fx942Cx9470x"
property Mnemonics : {"RCL", "ENM", "ReW", "EOC", "EDM", "RfW"}

set testCode to "9470"
my MnemonicOf(testCode)

on MnemonicOf(aCode)
	set oldDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {aCode}
	set theOffset to length of item 1 of text items of Codes
	set Mnem to (theOffset + 4) / 5
	return item Mnem of Mnemonics
	set AppleScript's text item delimiters to oldDelims
end MnemonicOf

Barry


> On 15 Mar 2015, at 21:33, Gil Dawson <email@hidden> wrote:
>
> 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)
> 	set Found to false
> 	repeat with k from 1 to the length of Codes
> 		if item k of Codes is equal to aCode then
> 			set ReturnResult to item k of Mnemonics
> 			set Found to true
> 			exit repeat
> 		end if
> 	end repeat
> 	if not Found...
>
> ...but is there another, perhaps faster, way to do this?
>
> 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.
>
> Any suggestions?
>
> --Gil
>
>
> _______________________________________________
> 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

 _______________________________________________
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


References: 
 >A question on technique (From: Gil Dawson <email@hidden>)

  • Prev by Date: Re: A question on technique
  • Next by Date: Re: A question on technique
  • Previous by thread: Re: A question on technique
  • Next by thread: Re: A question on technique
  • Index(es):
    • Date
    • Thread