Re: Passing *possible* variables to a handler
Re: Passing *possible* variables to a handler
- Subject: Re: Passing *possible* variables to a handler
- From: "Arthur J. Knapp" <email@hidden>
- Date: Fri, 12 Jul 2002 10:33:28 -0400
>
Date: Thu, 11 Jul 2002 17:52:50 -0700
>
From: Landis <email@hidden>
>
Subject: Passing *possible* variables to a handler
>
I want to pass a record that may or may not contain certain options
>
to a handler. This is what I've come up with, please tell me that
>
I'm overlooking some basic, much easier way to do this.
There is a basic, much easier way to do this. :)
>
(I'm also not positive I'm making sense, been staring at a screen too long)
You've made perfect sense. :)
>
property defC : 3 --default for C
>
property defD : 4 --default for D
>
>
on ThisHandler(varA, varB, varRec)
>
if varRec is "" then
>
set varRec to {varC:defC, varD:defD}
>
end if
>
try
>
set varC to varRec's varC
>
on error
>
set varC to defC
[snip]
You are looking for record concatenation:
on ThatHandler(paramRecord)
set defaultRecord to {a:1, b:2, c:3, d:4}
-- Record concatenation. All unique properties are
-- concatenated, and properties on the left overide
-- the same properties on the right.
--
if (paramRecord's class = record) then
set completeRecord to paramRecord & defaultRecord
else
set completeRecord to defaultRecord
end if
end ThatHandler
ThatHandler(0)
ThatHandler("")
ThatHandler(missing value) --> {a:1, b:2, c:3, d:4}
ThatHandler({b:"Hello"}) --> {b:"Hello", a:1, c:3, d:4}
ThatHandler({e:"f"}) --> {e:"f", a:1, b:2, c:3, d:4}
ThatHandler({a:4, b:3, c:2, d:1}) --> {a:4, b:3, c:2, d:1}
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
}
_______________________________________________
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.