TIDs store and restore WAS Re: AsciiNumber & AsciiCharacter Handlers
TIDs store and restore WAS Re: AsciiNumber & AsciiCharacter Handlers
- Subject: TIDs store and restore WAS Re: AsciiNumber & AsciiCharacter Handlers
- From: Paul Skinner <email@hidden>
- Date: Fri, 31 May 2002 17:04:22 -0400
While working on rewriting some handlers I looked into the whole
storing and restoring of the TIDs. I don't know that this technique is
novel, but it is concise, quick and creates no new variables.
This method exploits a bug in the TIDs that causes them to only use
the first item if the TIDs is a list. If this is ever fixed then this
technique will be broken.
. Store and change the TIDs...
set AppleScript's text item delimiters to {newDelimiter, item 1 of
(AppleScript's text item delimiters as list)}
Restore the TIDs...
set AppleScript's text item delimiters to {item 2 of AppleScript's text
item delimiters}
This method reminds me of Nigel's comment...
(Another idea I had - to set the 'beginning' of the delimiters to the
new value and then to reset them to their 'rest' afterwards - was
roundly (and rightly) sat upon by senior contributors to this group. ;-)
)
Hopefully I will not be similarly sat upon, but if anyone sees an
issue I'm sure they'll let it be known.
On Wednesday, May 8, 2002, at 09:14 AM, Nigel Garvey wrote:
Arthur J Knapp wrote on Tue, 07 May 2002 19:48:42 -0400:
Date: Tue, 7 May 2002 15:41:50 -0400
Subject: Re: AsciiNumber & AsciiCharacter Handlers
From: Paul Skinner <email@hidden>
Thanks to Arthur and has for the feedback!
Arthur, I really liked the TIDs swapping tell block!
I know everyone is really sick of my continuous stream of praise for
Nigel Garvey, ...
[Yawn...]
... but I'm pretty sure that I first saw that particular type
of tids-tell block in some code of his. :)
The block in question being:
tell (a reference to text item delimiters)
set {o, contents} to {contents, c}
set {i, contents} to {my kStr256's text item 1's length, o}
end tell
I did in fact come up with the idea of applying the setting-by-list
technique to TID's about three or four years ago - though I don't suppose
I'm the first or the only person to have done so. The aim at the time was
to relieve the drudgery of having to type 'set AppleScript's text item
delimiters to ...' for several lines in a row. Later, I added the "tell
reference" idea so that the expression 'AppleScript's text item
delimiters' could be mostly abbreviated to 'contents'. (Another idea I
had - to set the 'beginning' of the delimiters to the new value and then
to reset them to their 'rest' afterwards - was roundly (and rightly) sat
upon by senior contributors to this group. ;-) )
It's very inefficient code though and the above snippet takes about twice
as long to execute as its conventional counterpart. This is because of
the overheads involved behind the scenes in setting up the lists and the
reference. Nowadays, I tend to avoid both ideas. But there may be some
merit - if the TID's are changed a lot during the course of a script - in
having the reference precompiled as a property:
property TIDref : a reference to AppleScript's text item delimiters
So wherever you needed it, you could type something like this:
tell TIDref
set o to contents
set contents to c
set i to (count kStr256's text item 1)
set contents to o
end tell
... which is only about 12% slower than the conventional method.
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
--
Can't make "old8tracks" into a record.
Paul Skinner
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.