Re: Too simple to find an answer for...
Re: Too simple to find an answer for...
- Subject: Re: Too simple to find an answer for...
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 29 Jul 2004 14:21:48 -0700
That doesn't get the sum, Andrew, that just iterates through the list. The
result is the last list item left standing, which is 2. Not what he wants.
I think you must have intended to do this:
set MyNumberList to {5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2}
getSum(MyNumberList)
--> 58
on getSum(theList)
set theSum to 0
repeat with eachItem in theList
try
set theSum to theSum + (eachItem as number)
end try
end repeat
return theSum
end getSum
Bernardo, by keeping "as number" as Andrew proposes, it will allow you to
run the handler of lists of text numbers too, such as {"5", "4", "3", ....}
--
Paul Berkowitz
>
From: Andrew Oliver <email@hidden>
>
Date: Thu, 29 Jul 2004 13:33:46 -0700
>
To: Bernardo Hoehl <email@hidden>, Applescript Users
>
<email@hidden>
>
Subject: Re: Too simple to find an answer for...
>
>
And just what do you expect this script to do?
>
>
The 'summarize' command takes a block of text and tries to extract the
>
relevant content to a summary that highlights the important parts of the
>
document. It has no effect on a list of integers.
>
>
If what you're trying to do is sum (i.e. add) all the integers, you'll
>
either need to loop through them, or use some OSAX that can do it for you
>
(without checking, I'm guessing the Satimage OSAX will do this 0- it does
>
just about everything else ;) )
>
>
on getSum (theList)
>
set theSum to 0
>
repeat with eachItem in theList
>
try
>
set theSum to (eachItem as number)
>
end try
>
end repeat
>
return theSum
>
end getSum
>
>
Andrew
>
:)
>
>
On 7/29/04 12:36 PM, "Bernardo Hoehl" <email@hidden> wrote:
>
>
> I searched for apple's subroutines and my O'Reilly's Applescript book,
>
> and can't find an answer to this very simple one:
>
>
>
> set MyNumberList to {5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2}
>
>
>
> set x to the summarize of every item of MyNumberList --- error
>
>
>
> Thanks!
>
>
>
> Bernardo Hoehl
>
>
>
> Rio de Janeiro - Brazil
>
> _______________________________________________
>
> 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.
>
_______________________________________________
>
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.
_______________________________________________
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.