Re: Union of sets (lists
Re: Union of sets (lists
- Subject: Re: Union of sets (lists
- From: John W Baxter <email@hidden>
- Date: Sat, 11 Jan 2003 22:13:52 -0800
- Envelope-to: email@hidden
Because the quote is so long, I'm top-posting.
Two things:
1. You need to change the copy inside the repeat:
copy contents of i to end of FinalResult
adding contents of.
When you do that, you'll get a final result of
"e" (Script Debugger; New Script Editor) or item 3 of {"c", "d", "e"}
(Script Editor 1.9)
These are the same thing, represented differently.
And the cause of the "e" is in #2
2. It appears that the union handler is returning the control variable (i)
of the repeat loop. That must be the last thing it "sees", probably when
it's deciding that the loop is over. Make it return what you want...
>
end repeat
return FinalResult -- <----insert the return statement
>
end union
I think you had the return statement in the Script Editor version but not
the Script Editor 1.9 version, and you posted the latter.
Now, all three editors mentioned above give {"a", "b", "c", "d", "e"},
although Script Debugger takes 7 lines to do so.
--John
At 16:49 -0700 1/11/2003, Michelle Steiner wrote:
>
set SetA to {"a", "b"} -- elements for set A
>
set SetB to {"c", "d", "e"} -- elements for set B and so on....
>
set foo to union(SetA, SetB)
>
>
to union(a, b)
>
if (class of a is not list) or (class of b is not list) then
>
display dialog "Only lists can be used." buttons {"Cancel"}
>
default button 1
>
end if
>
>
if (count (a)) is greater than (count (b)) then
>
copy a to x
>
copy b to y
>
else
>
copy b to x
>
copy a to y
>
end if
>
set FinalResult to y
>
repeat with i in x
>
if (i is not in y) and (i is not in FinalResult) then
>
copy i to end of FinalResult
>
end if
>
end repeat
>
end union
>
>
But with Script Editor 2.0 beta, the result is:
>
{"a", "b", item 1 of {"c", "d", "e"}, item 2 of {"c", "d", "e"}, item 3
>
of {"c", "d", "e"}}
>
>
And with Script Editor 1.9, the result is:
>
item 3 of {"c", "d", "e"}
>
>
What is going wrong here?
>
>
--Michelle
>
>
"There's some good in the world, Mr. Frodo, and it's worth fighting
>
for."
>
_______________________________________________
>
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.
--
John Baxter email@hidden Port Ludlow, WA, USA
_______________________________________________
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.