Hi Raymond
"Raymond E. Griffith" wrote:
> 
> I am trying to work with the new array notation. Here is a
> simple script.
> 
> on mouseUp
>   put fld "A" into A
>   split A by return
>   put A + 1 into B
>   combine B using return
>   put B into fld "B"
> end mouseUp
> 
> In fld "A" I have the numbers 1 through 20. Upon combining
> B, the results are returned in a seemingly random order. The
> results are
> 
> 2.000000
> 11.000000
> 12.000000
> 13.000000
> 14.000000
> 15.000000
> 16.000000
> 17.000000
> 18.000000
> 19.000000
> 20.000000
> 3.000000
> 21.000000
> 4.000000
> 5.000000
> 6.000000
> 7.000000
> 8.000000
> 9.000000
> 10.000000
> 
> I have some questions. First, how can I get the results in
> the proper order? Using the sort command has not worked.
here you have to use repeat. then your example looks like

on mouseUp
   put fld "A" into A
   split A by return
   put A + 1 into B
   -- now combine using the key as line number
   repeat for each line i in the keys of B
        put B[i] into line i of C
   end repeat                   
   put C into fld "B"
 end mouseUp

or you can try this

split A by return
-- now A is a array with keys as numbers
combine A by return and comma
-- A is a liste with tho items per line
--  so you have the key as the first item in A
sort lines of A numeric by item 1 of each 


> Secondly, how can I control the precision of calculations
> using array math? Using       set number format to "0.##"
> does not work. Third, how can math functions other than
> addition and multiplication be done with arrays (other than,
> "for each element in A"). For example, exponentiation,
> taking logs, etc. (handy stuff in statistical analysis,
> BTW).
> 
> Yes, I know. My third question can easily be handled with
> element-by-element manipulation.
> 
> But I note that there is a difficulty with the new repeat
> form. The repeat for each form goes from lowest to highest,
> as in
> 
> put 0 into j
> repeat for each line in A
> add 1 to j
> put a*2 into line j of B
> end repeat
> 
> This will work because we can be assured that the repeat for
> each form ascends numerically.

> But in the case of an associative array, there is no
> assurance of this ascension, particularly because keys(A) is
> returned in such a strange order. Furthermore, not every
> associative array will be indexed as A[1], A[2], etc...
> 
> So how do I follow the ascension characteristics of
> something like this?
> 
>   repeat for each element i in A
>     put a*2 into B[same key as A]
>   end repeat

repeat for each line L in the keys of A
   put A[L] into B[L]
end repeat

in case you will be shure to go from lowest to highest key in a array, you
can you extents(Array) to get the min and max key. like

repeat with i= item 1 of extents(A) to item 2 of extents(A)
  put A[i] into B[i]
  -- or put A[i] into line i of B  -- if you like B to be a list
end repeat

> 
> I am excited about the possibilities. But the trouble with
> returning a split variable after combining is rather
> daunting. Any help would be appreciated.
> 
> Thanks,
> 
> Raymond
> 
> Archives: http://www.mail-archive.com/[email protected]/
> Info: http://www.xworlds.com/metacard/mailinglist.htm
> Please send bug reports to <[EMAIL PROTECTED]>, not this list.


-- 
Eugen Helbling
_____________________________________________________________________

   GINIT Technology GmbH        [EMAIL PROTECTED]
   Eugen Helbling                          www.ginit-technology.com
   Emmy-Noether-Str. 11                    phone:   +49-721-96681-0
   D-76131 Karlsruhe                       fax:   +49-721-96681-111

Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to