Re: Creating list references in handlers. Bad code or bug?
Re: Creating list references in handlers. Bad code or bug?
- Subject: Re: Creating list references in handlers. Bad code or bug?
- From: Paul Skinner <email@hidden>
- Date: Fri, 14 Sep 2001 17:17:12 -0400
on 9/14/01 1:43 PM, Emmanuel wrote:
>
At 17:50 +0200 14/09/01, Helmut Fuchs wrote:
>
>
>
> At 10:26 Uhr -0400 14.09.2001, Victor Yee wrote:
>
>> I think that the problem is a matter of scope. References can only
>
>> refer to top-level or global varaibles.
>
>
This is what I observed also, as I posted a few days ago. A reference to a
>
local variable defined in a given handler fails if used in another handler.
>
>
I would be very surprised if this was documented, since it is a bug.
>
>
As I stated in my post a few days ago, *this used to work before 1.4.3*.
>
>
I can prove it :-)
>
>
Emmanuel
I don't doubt either of you, but that's not what I found in this case.
I was playing around with a vanilla, non-recursive 'entireContentsOf'
handler and I wanted to get the speed benefits of using references to lists.
Thus my first post.
After today's replies I thought I'd have to pass a list reference into
the handler. But no.
Here's what I have currently, the references in the handler refer to
lists in the handler and work properly with 'the contents of'.
Speed isn't bad (for a non-OSAX solution) since it only iterates over
the folders.
This handler returns alias lists as opposed to a finder reference list.
Much better in my opinion. Another benefit of this handler is the grouping
of the output. You could call it like so to get just the files of the
hierarchy...
everyFile of theEntireContentsOf(path to the system folder)
Watch the indentations to clean up the list server wrap.
--begin script
set f to path to scripts folder
theEntireContentsOf(f)
return the result
on theEntireContentsOf(the sourceFolder)
set folderListReference to a reference to {}
set fileListReference to a reference to {}
----------
tell application "Finder"
try
copy ((every folder of the sourceFolder) as alias list) to
folderListReference
on error --1 item cannot be returned as 'alias list'. Known Finder
bug.
copy (((every folder of the sourceFolder) as alias) as list) to
folderListReference
end try
try
copy ((every file of the sourceFolder) as alias list) to
fileListReference
on error --1 item cannot be returned as 'alias list'. Known Finder
bug.
copy (((every file of the sourceFolder) as alias) as list) to
fileListReference
end try
end tell
----------
set theIndex to 1
repeat
try
set thisItem to item theIndex of folderListReference
tell application "Finder"
try
set folderListReference to folderListReference & ((every
folder of thisItem) as alias list)
on error --1 item cannot be returned as 'alias list'. Known
Finder bug.
set folderListReference to folderListReference &
(((every folder of thisItem) as alias) as list)
end try
try
set fileListReference to fileListReference & ((every
file of thisItem) as alias list)
on error --1 item cannot be returned as 'alias list'. Known
Finder bug.
set fileListReference to fileListReference & (((every
file of thisItem) as alias) as list)
end try
end tell
set theIndex to theIndex + 1
on error
exit repeat
end try
end repeat
----------
return {everyFolder:contents of folderListReference, everyFile:contents
of fileListReference, everyItem:contents of folderListReference & contents
of fileListReference}
end theEntireContentsOf
--end script
--
Paul Skinner
Entropy isn't what it used to be.