Re: Finalizing Script
Re: Finalizing Script
- Subject: Re: Finalizing Script
- From: "Arthur J. Knapp" <email@hidden>
- Date: Thu, 29 Aug 2002 15:51:20 -0400
>
Date: Wed, 28 Aug 2002 13:44:04 -0400
>
Subject: Finalizing Script
>
From: Greg Back <email@hidden>
>
I have written the following script, and am planning to post it to
>
applemods in the next couple of days. I was wondering if any of you
>
scripting experts had any tips for optimizing or simplifying the code.
>
script BaseLib
[snip]
A very nice script. :)
>
set wFlag to (wholePart [NOT-EQUAL] "0")
>
set fFlag to (fractionPart [NOT-EQUAL] ".0")
Question regarding the ScriptToEmail translation : Why is it thought
better to swap the "is not" equal sign with:
[NOT-EQUAL]
rather than the syntactically valid:
is not
>
if wFlag then
>
repeat with i from 1 to l
>
set wholenum to wholenum + ((offset of (character i of
>
[NO-BREAK]wholePart) in charString) - 1) * (startingBase ^ (l - i))
Since the above can be repeated many times, it may be worth it to
replace the "offset of" command with a faster text item delimiter method:
set wholenum to wholenum + [NO-BREAK]
(OffsetOf(charString, wholePart's item i) - 1) [NO-BREAK]
* (startingBase ^ (l - i))
where you've defined:
on OffsetOf(str, sub)
set o to text item delimiters
set text item delimiters to sub
set x to (str's text item 1's length) + 1
set text item delimiters to o
return x mod ((str's length) + 1)
end OffsetOf
or slightly speeder:
>
if wFlag then
set oldDelims to text item delimiters
>
repeat with i from 1 to l
set wholenum to wholenum + [NO-BREAK]
(OffsetOf_t(charString, wholePart's item i) [NO-BREAK]
- 1) * (startingBase ^ (l - i))
>
end repeat
set text item delimiters to oldDelim
where you've defined:
on OffsetOf_t(str, sub)
set text item delimiters to sub
tell str to ((text item 1's length) + 1) mod (length + 1)
end OffsetOf_t
>
if fFlag then
>
repeat with i from 2 to m
>
set fractionNum to fractionNum + ((offset of (character i
>
[NO-BREAK]of fractionPart) in charString) - 1) / (startingBase ^ (i -
>
[NO-BREAK]1))
Same thing here:
set fractionNum to fractionNum + ,
(OffsetOf(charString, fractionPart's item i) [NO-BREAK]
- 1) / (startingBase ^ (i - i))
P.S. [NO-BREAK]
P.P.S. OK, now you can [BREAK]
;-)
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
}
_______________________________________________
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.