Re: Meeting a matrix of conditions
Re: Meeting a matrix of conditions
- Subject: Re: Meeting a matrix of conditions
- From: Graff <email@hidden>
- Date: Tue, 14 Sep 2004 08:38:58 -0400
You can do it with a record, which at least makes it a bit more
readable:
----
set keyValuePairs to {¬
{theKey:{"av", "bx", "bw", "bz", "dx", "ev"}, value:"apple"}, ¬
{theKey:{"aw", "cv", "dy", "dz", "ez"}, value:"orange"}, ¬
{theKey:{"ax", "cw", "cx", "ey"}, value:"banana"}, ¬
{theKey:{"ay", "cz", "dv", "ew"}, value:"mango"}, ¬
{theKey:{"az", "bv", "by", "cy", "dw", "ex"}, value:"tomato"}}
set x to some item of {"a", "b", "c", "d", "e"}
set y to some item of {"v", "w", "x", "y", "z"}
repeat with aPair in keyValuePairs
if (x & y) is in theKey of aPair then
set z to value of aPair
end if
end repeat
----
- Ken
On Sep 14, 2004, at 1:40 AM, Joseph Weaks wrote:
I figure there must be a more clever & efficient way to do this:
set x to some item of {"a", "b", "c", "d", "e"}
set y to some item of {"v", "w", "x", "y", "z"}
if (x & y) is in {"av", "bx", "bw", "bz", "dx", "ev"} then
set z to "apple"
else if (x & y) is in {"aw", "cv", "dy", "dz", "ez"} then
set z to "orange"
else if (x & y) is in {"ax", "cw", "cx", "ey"} then
set z to "banana"
else if (x & y) is in {"ay", "cz", "dv", "ew"} then
set z to "mango"
else if (x & y) is in {"az", "bv", "by", "cy", "dw", "ex"} then
set z to "tomato"
end if
I figured coercing into one string was better than if x = "a" and y =
"v" then...
My code breaks it down into many more "else if"'s. The y list in my
code actually has about twice this many items.
Ideas on a better way to accomplish this?
Thanks,
Joe Weaks
P.S. Sorry for the poor topic. I could not figure out what to call
this arrangement. _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden