• 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: Deivy Petrescu <email@hidden>
  • Date: Sun, 15 Mar 2015 20:40:13 -0400

> On Mar 15, 2015, at 19:14 , Deivy Petrescu <email@hidden> wrote:
>
>
>> On Mar 15, 2015, at 17: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
>>
>>
> I don’t know the OS nor the idea of the whole script.
> So two suggestions:
>
> 1. AppleScript
>
> <script>
> property Codes : {"9420", "94ae", "94d0", "942f", "942C", "9470"}
> property Mnemonics : {"RCL", "ENM", "ReW", "EOC", "EDM", "RfW"}
> tid(space)
> set TCodes to Codes as string
> set TMnemonics to Mnemonics as string
>
> set k to round (offset of "9470" in TCodes) / 5 rounding up
> set j to round (offset of "ENM" in TMnemonics) / 4 rounding up
>
> return {k, j}
> —>{6,2}
> </script>
>
> The script above assumes all the items are of the same length (4 in Codes and 3 in Mnemonics) you can make minor changes to accommodate the variation.

Sorry, I forgot to add the ti handler in the script above


on tid(x)
	set AppleScript's text item delimiters to x
end tid

>
> 2. Javascript
>
> <script>
> Codes = ["9420", "94ae", "94d0", "942f", "942C", "9470"]
> Mnemonics = ["RCL", "ENM", "ReW", "EOC", "EDM", "RfW"]
>
>
> Mnemonics.indexOf("EOC")
> </script>
> —>3
>
> Deivy Petrescu
> 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

Deivy Petrescu
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


  • Follow-Ups:
    • Re: A question on technique
      • From: "Stockly, Ed" <email@hidden>
References: 
 >A question on technique (From: Gil Dawson <email@hidden>)
 >Re: A question on technique (From: Deivy Petrescu <email@hidden>)

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