• 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 19:38:11 -0500

On Mar 24, 2015, at 18:06, Shane Stanley <email@hidden> wrote:
In terms of the rosettacode definition of the problem, it's also closer to correct because it keeps punctuation. (An arbitrary decision, no?)
______________________________________________________________________

Hey Shane,

My example wasn't designed to solve the problem formulated by Rosetta Code.  It was just a very simple word-reverser.

I agree that the problem on Rosetta Code is a bit under-explained.

They should have provided both before and after examples with the ability to copy the exact text.

They should also have discussed the possibility (or lack thereof) of leading and trailing whitespace per line.

To tackle that example with the Satimage.osax I'd do something like this:

-------------------------------------------------------------------------------------------
# Requires the Satimage.osax { http://tinyurl.com/dc3soh }

set _str to text 2 thru -2 of "
---------- Ice and Fire ------------

 

fire, in end will world the say Some
ice. in say Some                    
desire of tasted I've what From     
fire. favor who those with hold I   

 

... elided paragraph last ...       

 

Frost Robert -----------------------
"

reverseWords(_str)

on reverseWords(_str)
  set _str to change "^[[:blank:]]+|[[:blank:]]+$" into "" in _str with regexp
  set _list to paragraphs of _str
  repeat with i in _list
    set contents of i to join (reverse of (splittext (contents of i) using "[[:blank:]]+" with regexp)) using " "
  end repeat
  return join _list using linefeed
end reverseWords
-------------------------------------------------------------------------------------------

Although this is still quite simplistic.

Back in the days when I could use Eudora I ran a reformatter script on every reply and forward that was about 1200 lines.

The last year I used Eudora was 2005, and even on my old mirror door Mac Pro with Tiger it ran in a flash.

Most of the script was find/replace routines using the Satimage.osax with customizations for various email lists and such.

Monkeying with complex punctuation is a pain and required quite a lot of creativity.

--
Take Care,
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>)
 >Re: Algorithms in Applescript (From: Christopher Stone <email@hidden>)
 >Re: Algorithms in Applescript (From: Shane Stanley <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