calculate each element of an array

Steve Kane skane at skaneco.com
Tue Feb 12 18:02:49 PST 2008


On Feb 12, 2008, at 4:28 PM, Mark Terry wrote:

>
> On Feb 12, 2008, at 12:23 PM, Steve Kane wrote:
>
>> I'd like to calculate, ie do the arithmetic, on each element of a
>> carriage return separated array.
>>
>> The array looks like this:
>>
>> 3*2
>> 4*3
>> 7+3
>> 8/4
>> 9-2
>>
>> I'd like to get a second array that looks like:
>>
>> 6
>> 12
>> 10
>> 2
>> 7
>>
>> I know I should be able to find this in the docs but I can't seem to.

> How about this:
> local RA,EXE
> RA="3*2
> 4*3
> 7+3
> 8/4
> 9-2"
>
> ArrayFilter RA,EXE,¶,
> {str(}+import()+{)}
> EXE="RA="+replace(EXE,¶,"+¶+")
> EXECUTELOCAL EXE
> message RA
>
> Not exactly elegant, but it works.

I changed it to:

local RA,EXE
RA=display1 ; my input field
ArrayFilter RA,EXE,¶,
{str(}+import()+{)}
EXE="RA="+replace(EXE,¶,"+¶+")
EXECUTELOCAL EXE
display2 = RA ; my output field

And it worked immediately.

The previously offered solutions will be fun to try to figure out.

Thanks.

Steve



More information about the Qna mailing list