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:
-------------------------------------------------------------------------------------------
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
|