Re: Appending a list to a list and getting one list.
Re: Appending a list to a list and getting one list.
- Subject: Re: Appending a list to a list and getting one list.
- From: Paul Skinner <email@hidden>
- Date: Tue, 14 May 2002 14:24:51 -0400
Thanks for the help everyone.
On Tuesday, May 14, 2002, at 09:38 AM, Arthur J Knapp wrote:
Date: Mon, 13 May 2002 12:40:02 -0400
Subject: Appending a list to a list and getting one list.
From: Paul Skinner <email@hidden>
set bigList to {}
set bigListRef to a reference to bigList
set numItems to 10000
set t to (time of (current date)) --Start timing operations.
repeat with n from 1 to numItems
set bigListRef to bigListRef & n --SuperSlowDowner!
It sure is a super-slow-downer, primarily because after the first
iteration, bigListRef is no longer a reference, but the actual value
of "bigListRef & n".
True, it is dereferencing it, but that's not the primary cause for
the slowdown. In fact the script executes in the same time if this step
is altered to NOT dereference bigListRef. Concatenation is the lead
weight here.
You want to do any of the following:
set contents of bigListRef to bigListRef & n --> dereference
set bigList to bigListRef & n --> this does not affect the reference
Nor does this option affect the speed of the script.
set bigListRef's end to n --> append
I'd love to do this but it gives me a list of lists when n is a list.
That and the speed of concatenation was the impetus for my post.
On Tuesday, May 14, 2002, at 08:03 AM, has wrote:
But given the circumstances, I don't see any point in doing more copy
operations than is necessary. I would simply use:
repeat with n from 1 to numItems
set the end of bigListRef to n
end repeat
repeat with n from 1 to numItems
set bigListRef to bigListRef & n --SuperSlowDowner!
end repeat
Paul Skinner wrote:
[...]
The example made me think that they are doing a similar thing
(concatenating) in the 10K iterations as they show prior to it. Not so.
What a huge red herring. Sorry. That should have read...
'The example made me think that they are doing a similar thing
(APPENDING) in the 10K iterations as they show prior to it. Not so.'
'list1 & list2' is a concatenation. AS creates a new list by copying
all of
the content from list1 to a new memory location, and copying all of the
content from list2 to the end of that.
'set end of theList to someValue' is not. It changes the existing
theList
by appending someValue to it.
Right. And it's what I want to do. I just don't want to get the results
applescript gives. I want one list from two APPENDED lists. So far no
luck.
Can anyone tell me how to append a list to a list and get just one
list?
Concatenation. Or, as Lachlan suggests, appending the items from the
second
list to the first one at a time.
Neither of which is appending two lists. Neither of which is fast.
I think this line of thinking is just a dead alley. I'll just
concatenate and wait. Thanks again to all for the input.
--
Paul Skinner
_______________________________________________
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.