Re: Passing *possible* variables to a handler
Re: Passing *possible* variables to a handler
- Subject: Re: Passing *possible* variables to a handler
- From: has <email@hidden>
- Date: Fri, 12 Jul 2002 12:40:06 +0100
Landis wrote:
>
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. I'm at a
>
loss.
Not far off. This ongoing lack of full support for optional parameters in
function calls is a bear. Most languages seem to have no problem providing
these, but AS (for whatever reason) supports them for calls sent to
applications/osaxen but not for calls made to scripts. (AS weird, tho' we
loves it anyways...)
I prefer using a record concatenation over try blocks: it's simpler,
shorter and more reliable.
======================================================================
on ThisHandler(paramRec)
(*
paramRec is a record containing the following properties:
varA (required)
varB (required)
varC (optional)
varD (optional)
*)
set paramRec to paramRec & {varC:3, varD:4}
--
--test
log paramRec's varA
log paramRec's varB
log paramRec's varC
log paramRec's varD
end ThisHandler
ThisHandler({varA:1, varB:2, varC:6})
--ansA=1
--ansB=2
--ansC=6
--ansD=4
======================================================================
Ugly and clumsy, but in the absence of anything better it does the job. I
prefer an all-or-nothing approach for consistency's sake: if one or more
parameters are 'optional', I'll pass all of them via a record. I'd
recommend clearly documenting the handler so it's easy to see what
properties are expected in paramRec, and which are required and which are
optional.
HTH
has
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
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.