Re: list of lists as arrays - creating?
Re: list of lists as arrays - creating?
- Subject: Re: list of lists as arrays - creating?
- From: Arthur J Knapp <email@hidden>
- Date: Tue, 02 Apr 2002 12:44:21 -0500
>
Date: Tue, 02 Apr 2002 00:40:24 -0800
>
Subject: Re: list of lists as arrays - creating?
>
From: Paul Berkowitz <email@hidden>
>
On 4/1/02 11:53 PM, "email@hidden" <email@hidden> wrote:
>
> Specific Question: does a list of lists (i.e. - a 2 dimensional array) have
>
> to be dimensioned in some way in order to bring it into existance?
>
set OurFileWidth to 100
>
set OurFileHeight to 100
>
try
>
set TheTestArray to {}
>
repeat OurFileWidth times
>
set end of my TheTestArray to {}
>
end repeat
>
repeat with Width from 1 to OurFileWidth
>
repeat OurFileHeight times
>
set end of item Width of my TheTestArray to "0"
>
[Side issue: The two 'my's in there (at least the second one) make it _much_
>
faster, if that's what you want. 'my TheTestArray' won't work in a handler,
>
however, unless TheTestArray was defined at the top level of a script as a
>
property or global, or passed as a parameter to the handler. You can use
>
script objects within handlers to do the same, thanks to a discovery of
>
Serge Belleudy-d'Espinose on the MacScrpt list. The 'my' in main scripts is
>
a refinement of Nigel Garvey's. Ask if you want to know the details about
>
handlers.]
[Addendum to Paul's Side issue: Here is an example of a constructed
script object whose methods should give you faster access to it's
items.]:
on newArrayXY(x, y)
script ArrayXY
property thisArray : {}
on GetAt(x, y)
return my thisArray's item x's item y
end GetAt
on SetAt(x, y, v)
set my thisArray's item x's item y to v
end SetAt
end script
repeat (x) times
set ArrayXY's thisArray's end to {}
repeat (y) times
set ArrayXY's thisArray's item -1's end to 0
end repeat
end repeat
return ArrayXY
end newArrayXY
set myArray to newArrayXY(100, 100)
tell myArray
SetAt(1, 1, "a")
SetAt(1, 2, "b")
SetAt(1, 3, "c")
GetAt(1, 1) --> "a"
GetAt(1, 2) --> "b"
GetAt(1, 3) --> "c"
end tell
Another nice thing about constructed script objects, (those that
are returned from handlers), is that you can use them to initialize
data-structures at the time the script is compiled, instead of each
time the script is run:
on newArrayXY(x, y)
...
end newArrayXY
property pArray : newArray(100, 100) --> Ready to go at run-time.
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
<
mailto:email@hidden>
try
<
http://homepage.mac.com/ewalet/DeskTop.html>
on error number -128
end try
}
_______________________________________________
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.