• 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: Algorithms in Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Algorithms in Applescript


  • Subject: Re: Algorithms in Applescript
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 24 Mar 2015 16:13:48 -0500

On Mar 24, 2015, at 05:30, Jean-Christophe Helary <email@hidden> wrote:
I was looking for a Levenshtein distance in Applescript and found that the Rosetta page had a *lot* of algorithms not implemented in Applescript.
______________________________________________________________________

Hey Jean-Christophe,

AppleScript in and of itself is painfully sparse.

However ASObjC has raised the bar way, way up despite its complexity.

It's a shame there's not a CPAN-like entity for AppleScript, because many of those algorithms (and other goodies) have been implemented by one scripter or another over the last 20 years.

One example:

set _str to "Now is the time for all good men to come to the aid of their country"

set newStrA to reverseWordsofString(_str)
set newStrB to reverseWordsofStringBetter(_str)

-------------------------------------------------------------------------------------------
on reverseWordsofString(_str)
  set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
  set newStr to (reverse of (words of _str)) as text
  set AppleScript's text item delimiters to oldTIDS
  return newStr
end reverseWordsofString
-------------------------------------------------------------------------------------------
on reverseWordsofStringBetter(_str)
  set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
  set newStr to (reverse of (text items of _str)) as text
  set AppleScript's text item delimiters to oldTIDS
  return newStr
end reverseWordsofStringBetter
-------------------------------------------------------------------------------------------

The reason method 2 is better is because you cannot depend upon AppleScript to define words the same way you do.

Whereas you have control over what AppleScript's text item delimiters do.

I personally would probably use the Satimage.osax:

set newStrC to join (reverse of (splittext _str using " +" with regexp)) using " "

--
Best Regards,
Chris

 _______________________________________________
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: Algorithms in Applescript
      • From: Shane Stanley <email@hidden>
References: 
 >Algorithms in Applescript (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: Re: Algorithms in Applescript
  • Next by Date: Re: Algorithms in Applescript
  • Previous by thread: Re: Algorithms in Applescript
  • Next by thread: Re: Algorithms in Applescript
  • Index(es):
    • Date
    • Thread